【问题标题】:Sending mail via Gmail SMTP with PHP Zend error - UGFzc3dvcmQ6使用 PHP Zend 错误通过 Gmail SMTP 发送邮件 - UGFzc3dvcmQ6
【发布时间】:2011-10-16 15:37:38
【问题描述】:

我正在尝试使用 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 或服务器或其他什么?还是我应该用其他帐户试试?

【问题讨论】:

  • 当您尝试使用另一台邮件服务器(即来自您的互联网提供商的服务器)发送邮件时会发生什么?
  • @Arjan 我无法访问允许 PHP mail() 的 Web 主机,我将仅在 localhost 上使用此脚本。除非你的意思是使用 gmail 以外的东西发送? - 我已尝试连接到我的 hotmail 帐户,但出现“5.0.0 身份验证失败”。

标签: php smtp gmail zend-mail


【解决方案1】:

您需要对外发邮件使用 SSL / OAuth,而 Google 有 this page 关于如何设置的信息。他们还有一个关于 problems sending mail 的页面,说明您需要 SSL(并链接到有关如何配置电子邮件客户端的另一个页面)。

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

【讨论】:

  • 将 TLS 更改为 SSL 时出现相同的错误。尝试 OAuth 是最好的解决方案吗? - 我也想使用其他邮件帐户。此外,google's oauth page 上 PHP 下的链接似乎已损坏。
  • 奇怪,所有示例页面(Java、Python、PHP)及其下载都对我有用。我在那里没有任何损坏的链接。如果 TSL 和 SSL 不适合您,您应该尝试 OAuth。直接链接到 Google OAuth PHP 示例下载(zip 文件):google-mail-xoauth-tools.googlecode.com/files/…。该链接对我有用,我得到一个 zip 文件并可以将其解压缩。
  • 感谢您的帮助。这些页面现在对我有用,但是我通过使用 PHPMailer 和 Sendmail 而不是 Zend 得到了我想要的。
猜你喜欢
  • 2011-08-11
  • 1970-01-01
  • 2012-05-29
  • 1970-01-01
  • 2018-05-13
  • 2014-03-16
  • 1970-01-01
  • 2017-05-12
  • 2021-05-08
相关资源
最近更新 更多