2011-07-30 119 views
0

我想使用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或服務器或其他?或者我應該嘗試與另一個帳戶?

+0

當您嘗試使用其他郵件服務器(即您的互聯網提供商提供的郵件服務器)發送郵件時會發生什麼? – Arjan

+0

@Arjan我無法訪問允許使用PHP郵件的Web主機(),我將僅在本地主機上使用此腳本。除非你的意思是使用gmail以外的其他方式進行發送? - 我嘗試連接到我的Hotmail帳戶,但只是「5.0.0身份驗證失敗」。 – Zendmailer

回答

0

您需要將SSL/OAuth用於發送郵件,Google需要使用this page來說明如何設置。他們還有一個關於problems sending mail的頁面,解釋說您需要SSL(並且鏈接到另一個頁面上關於如何配置電子郵件客戶端)。

我不知道Zend郵件,你可能會配置使用SSL。

+0

我將TLS更改爲SSL時出現相同的錯誤。正在嘗試OAuth的最佳解決方案? - 我想使用其他郵件帳戶。此外,[google的oauth頁面](http://code.google.com/apis/gmail/oauth/code.html)上的PHP鏈接似乎已被破壞。 – Zendmailer

+0

奇怪的是,所有示例頁面(Java,Python,PHP)及其下載都適用於我。我沒有得到任何斷開的鏈接。如果TSL和SSL不適合你,你應該嘗試OAuth。直接鏈接到Google OAuth PHP示例下載(zip文件):http://google-mail-xoauth-tools.googlecode.com/files/xoauth-php-samples.zip。該鏈接適用於我,我得到一個zip文件,並可以解壓縮它。 – Arjan

+0

感謝您的幫助。這些頁面現在正在爲我工​​作,但是我通過使用PHPMailer和[Sendmail](http://www.joshstauffer.com/send-test-emails-with-wampserver/)而不是Zend獲得了我想要的內容。 – Zendmailer