转自: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);
}