首页 | PHP资讯 | 技术专栏 | 资源共享 | PHP培训 | PHP职场 | 图书 | PHP ON WIN | PHP圈子 | PHPer学习大本营
返回列表 回复 发帖

给Zend_Mail增加SMTP验证功能

给Zend_Mail增加SMTP验证功能

本帖最后由 七月十五 于 2009-5-16 13:21 编辑

zend mail现在还未支持验证, 我刚刚修改了一下.

在Zend_Mail_Transport_Smtp类
修改如下
    public function __construct($host, $port=25, $myName='127.0.0.1', $auth=false,$user='',$pass='')
    {
        $this->_host = $host;
        $this->_port = $port;
        $this->_myName = $myName;
        
        $this->_auth = $auth; //Added for Smtp Auth by Vicnent
        $this->_user = $user;
        $this->_pass = $pass;
    }


   public function connect()
    {
        $errno  = null;
        $errstr = null;

        // open connection
        $fp = stream_socket_client('tcp://'.$this->_host.':'.$this->_port, $errno, $errstr, self::CONNECTION_TIMEOUT);

        if ($fp===false) {
            if ($errno==0) {
                $msg = 'Could not open socket';
            } else {
                $msg = $errstr;
            }
            throw new Zend_Mail_Transport_Exception($msg);
        }

        $this->_con = $fp;

        try {
            $res = stream_set_timeout($this->_con, self::COMMUNICATION_TIMEOUT);
            if ($res === false) {
                throw new Zend_Mail_Transport_Exception('Could not set Stream Timeout');
            }

            /**
             * Now the connection is open. Wait for the welcome message:
             *   welcome message has error code 220
             */
            $this->_expect(220);
            $this->helo($this->_myName);
            
            if ($this->_auth){
                $this->authUser($this->_user);
                $this->authPass($this->_pass);
            }
            
        } catch (Zend_Mail_Transport_Exception $e) {
            fclose($fp);
            throw $e;
        }
    }




增加下面两个方法
    public function authUser($user)
    {
        $this->_send('AUTH LOGIN ');   
        $this->_expect(334);
        $this->_send(base64_encode($user));   
        $this->_expect(334);        
    }
   
    public function authPass($pass)
    {
        $this->_send(base64_encode($pass));   
        $this->_expect(235);
    }

返回列表