我想使用Zend框架發送郵件與Gmail,但一直無法這樣做,因爲它似乎拒絕用戶名和密碼(我可以使用登錄到gmail.com和Outlook等)。發送郵件通過Gmail SMTP與PHP Zend錯誤 - UGFzc3dvcmQ6
我的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('[email protected]', '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的\郵件\協議\ 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
@Arjan我無法訪問允許使用PHP郵件的Web主機(),我將僅在本地主機上使用此腳本。除非你的意思是使用gmail以外的其他方式進行發送? - 我嘗試連接到我的Hotmail帳戶,但只是「5.0.0身份驗證失敗」。 – Zendmailer