我是小佳 ,未注明原创的,均为转载。

给Zend_Mail SMTP增加验证功能

上一篇 / 下一篇  2006-10-08 09:38:33 / 天气: 晴朗 / 心情: 高兴 / 个人分类:PHP杂谈

转自:http://www.phpchina.cn/bbs/thread-7919-1-2.html

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);
    }

TAG: PHP杂谈

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

数据统计

  • 访问量: 39924
  • 日志数: 121
  • 图片数: 1
  • 文件数: 1
  • 书签数: 27
  • 建立时间: 2006-09-21
  • 更新时间: 2007-08-12

RSS订阅

Open Toolbar