日期:2013-03-23  浏览次数:20704 次

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));
        
  &n