0

我正在尝试使用 Zend 框架通过 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 编码的“密码:”,但是“fx12sm2756834wbb.59”是什么意思,我该如何解决这个错误 - 我应该更改端口还是 ssl 或 auth 或服务器或其他什么?还是我应该用另一个帐户试试?

4

1 回答 1

0

您需要使用 SSL / OAuth 来发送邮件,谷歌有这个关于如何设置的页面。他们还有一个关于发送邮件问题的页面,说明您需要 SSL(并链接到有关如何配置电子邮件客户端的另一个页面)。

我不了解 Zend 邮件,您可能可以将其配置为使用 SSL。

于 2011-07-30T20:35:44.957 回答