我正在尝试使用Zend Framework通过Gmail发送邮件,但一直无法这样做,因为它似乎拒绝了用户名和密码(我可以用来登录到gmail.com和Outlook等)。
我的PHP代码是:
<?php
$tr = new Zend_Mail_Transport_Smtp("smtp.gmail.com",array('user' => '****@gmail.com', 'password' => '****', 'auth' => 'login', 'ssl' => 'TLS'));
Zend_Mail::setDefaultTransport($tr);
$mail = new Zend_Mail();
$mail->setFrom('sender@example.com', 'Some Sender');
$mail->addTo('****@hotmail.com', 'Some Recipient'); // my Hotmail account
$mail->setSubject('Test Subject');
$mail->setBodyText('This is the text of the mail.');
try {
$sent = $mail->send($tr);
} catch (Zend_Mail_Exception $e) {
die($e);
}
?>Zend抛出的异常是:
exception 'Zend_Mail_Protocol_Exception' with message 'UGFzc3dvcmQ6
' in C:\Users\Admin\Documents\Wamp\bin\php\php5.3.0\lib\Zend\Mail\Protocol\Abstract.php:431
Stack trace:
#0 C:\Users\Admin\Documents\Wamp\bin\php\php5.3.0\lib\Zend\Mail\Protocol\Smtp\Auth\Login.php(95): Zend_Mail_Protocol_Abstract->_expect(235)
#1 C:\Users\Admin\Documents\Wamp\bin\php\php5.3.0\lib\Zend\Mail\Protocol\Smtp.php(217): Zend_Mail_Protocol_Smtp_Auth_Login->auth()
#2 C:\Users\Admin\Documents\Wamp\bin\php\php5.3.0\lib\Zend\Mail\Transport\Smtp.php(200): Zend_Mail_Protocol_Smtp->helo('localhost')
#3 C:\Users\Admin\Documents\Wamp\bin\php\php5.3.0\lib\Zend\Mail\Transport\Abstract.php(348): Zend_Mail_Transport_Smtp->_sendMail()
#4 C:\Users\Admin\Documents\Wamp\bin\php\php5.3.0\lib\Zend\Mail.php(1194): Zend_Mail_Transport_Abstract->send(Object(Zend_Mail))
#5 C:\Users\Admin\Documents\Wamp\www\Reader\scripts\modules\mail\send.php(63): Zend_Mail->send(Object(Zend_Mail_Transport_Smtp))
#6 {main}通过进入Zend\Mail\Protocol\Abstract.php,我发现完整的$errMsg是:
UGFzc3dvcmQ6
5.7.1 Username and Password not accepted. Learn more at
5.7.1 http://mail.google.com/support/bin/answer.py?answer=14257 fx12sm2756834wbb.59我知道UGFzc3dvcmQ6是用base64编码的"Password:“,但是"fx12sm2756834wbb.59”是什么意思,我如何修复这个错误--我应该改变端口、ssl、身份验证、服务器或其他什么东西吗?或者我应该用另一个账号试试?
发布于 2011-07-31 04:35:45
你需要使用SSL / OAuth发送邮件,谷歌有this page告诉你如何设置。他们也有一个关于problems sending mail的页面,解释你需要SSL (并链接到另一个关于如何配置电子邮件客户端的页面)。
我不知道Zend mail,你也许可以配置它使用SSL。
https://stackoverflow.com/questions/6885304
复制相似问题