• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    支持stmp認證、HTML格式郵件的類

    發布: 2007-7-14 19:53 | 作者: 佚名    | 來源: 網絡轉載     | 查看: 9次 | 進入軟件測試論壇討論

    領測軟件測試網 c_smtp_client.php
    <?php
    /* smtp client class */
    class c_smtp_client
    {
        var $connection;
        var $server;
        var $elog_fp;
        var $log_file='./smtp_client.log';
        var $do_log=true;
        var $need_auth=true;
        var $username;
        var $password;

        // 構造器
        function c_smtp_client($server='')
        {
            if (!$server)
            {
                $this->server="localhost";
            }
            else
            {
                $this->server=$server;
            }

            $this->connection = fsockopen($this->server, 25);
            if ($this->connection <= 0) return 0;
            fputs($this->connection,"HELO xyz\r\n");
        }
        
        function email($from_mail, $to_mail, $to_name, $header, $subject, $body)
        {
            if ($this->connection <= 0) return 0;
            
            // 郵件用戶認證
            if ($this->need_auth)
            {
                $this->elog("AUTH LOGIN", 1);
                fputs($this->connection,"AUTH LOGIN\r\n");
                $this->elog(fgets($this->connection, 1024));
                 
                $base64_username=base64_encode($this->username);
                $this->elog("$base64_username", 1);
                fputs($this->connection,"$base64_username\r\n");
                $this->elog(fgets($this->connection, 1024));

                $base64_password=base64_encode($this->password);
                $this->elog("$base64_password", 1);
                fputs($this->connection,"$base64_password\r\n");
                $this->elog(fgets($this->connection, 1024));
            }

            $this->elog("MAIL FROM:$from_mail", 1);
            fputs($this->connection,"MAIL FROM:$from_mail\r\n");
            $this->elog(fgets($this->connection, 1024));
            
            $this->elog("RCPT TO:$to_mail", 1);
            fputs($this->connection, "RCPT TO:$to_mail\r\n");
            $this->elog(fgets($this->connection, 1024));
            
            $this->elog("DATA", 1);
            fputs($this->connection, "DATA\r\n");
            $this->elog(fgets($this->connection, 1024));

            $this->elog("Subject: $subject", 1);
            $this->elog("To: $to_name", 1);
            fputs($this->connection,"Subject: $subject\r\n");
            fputs($this->connection,"To: $to_name\r\n");

            if ($header)
            {
                $this->elog($header, 1);
                fputs($this->connection, "$header\r\n");
            }

            $this->elog("", 1);
            $this->elog($body, 1);
            $this->elog(".", 1);
            fputs($this->connection,"\r\n");
            fputs($this->connection,"$body \r\n");
            fputs($this->connection,".\r\n");
            $this->elog(fgets($this->connection, 1024));

            return 1;
        }


        function send()
        {
            if ($this->connection)
            {
                fputs($this->connection, "QUIT\r\n");
                fclose($this->connection);
                $this->connection=0;
            }
        }

        function close()
        {
            $this->send();
        }

        function elog($text, $mode=0)
        {
            if (!$this->do_log) return;

            // open file
            if (!$this->elog_fp)
            {
                if (!($this->elog_fp=fopen($this->log_file, 'a'))) return;
                fwrite($this->elog_fp, "\n-------------------------------------------\n");
                fwrite($this->elog_fp, " Sent " . date("Y-m-d H:i:s") . "\n");
                fwrite($this->elog_fp, "-------------------------------------------\n");
            }

            // write to log
            if (!$mode)
            {
                fwrite($this->elog_fp, "    $text\n");
            }
            else
            {
                fwrite($this->elog_fp, "$text\n");
            }
        }
    }
    ?>



    c_mail.php
    <?php

        /* 郵件發送類 */
        require_once dirname(__FILE__)."/c_smtp_client.php";
        static $c_smtp_client;
        if(!isset($c_smtp_client))
        {
            $c_smtp_client              =    & new c_smtp_client($smtp_server['name']);
            $c_smtp_client->do_log      =    false;
            $c_smtp_client->need_auth   =    $smtp_server['need_auth'];
            $c_smtp_client->username    =    $smtp_server['username'];
            $c_smtp_client->password    =    $smtp_server['password'];    
        }

        class c_mail
        {
            // html格式的Mail信箋
            function html_mailer($from_name,$from_mail,$to_name,$to_mail,$subject,$message,$reply_mail)
            {
                $headers     =    "";
                $headers    .=    "MIME-Version: 1.0\r\n";
                $headers    .=    "Content-type: text/html; charset=gb2312\r\n";
                $headers    .=    "From: ".$from_name."<".$from_mail.">\r\n";
                $headers    .=    "To: ".$to_name."<".$to_mail.">\r\n";
                $headers    .=    "Reply-To: ".$from_name."<".$reply_mail.">\r\n";
                $headers    .=    "X-Priority: 1\r\n";
                $headers    .=    "X-MSMail-Priority: High\r\n";
                $headers    .=    "X-Mailer: WebCMS MAIL SERV";

                // 開始發送郵件
                if($smtp_server['name']=='')
                {
                    @mail($to_mail, $subject, $message, $headers);
                }
                else
                {
                    $c_smtp_client->email($from_mail,$to_mail,$to_name,$headers,$subject,$message);
                    $c_smtp_client->send();        
                }
            }
    }
    ?>


    config.inc.php
    <?php
        //smtp_server['name']=='';則表示直接使用mail();          
        //smtp_server['name']=='localhost';表示程序所在主機的smtp服務器
        $smtp_server['name']            =    "";
        $smtp_server['need_auth']       =    true;
        $smtp_server['username']        =    '';
        $smtp_server['password']        =    '';
    ?>


    sendmail.php
    <?php
        //調用方法
        require_once dirname(__FILE__)."/config.inc.php";
        require_once dirname(__FILE__)."/c_mail.php";
        $c_mail    = new c_mail();
        $c_mail->html_mailer($from_name,$from_mail,$to_name,$to_mail,$subject,$message,$reply_mail);

    ?>

    文章來源于領測軟件測試網 http://www.kjueaiud.com/


    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備10010545號-5
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>