I am trying to use the Zend Framework to send mail with Gmail, but have been unable to do so because it seems to reject the username and password (which I can use to login to gmail.com and with Outlook etc).
My PHP code is:
<?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 ac开发者_如何学编程count
$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);
}
?>
The exception thrown by Zend is:
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}
By going into Zend\Mail\Protocol\Abstract.php I found that the full $errMsg was:
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
I know that UGFzc3dvcmQ6 is "Password:" encoded in base64, but what does "fx12sm2756834wbb.59" mean, and how can I fix the error - should I be changing the port or ssl or auth or server or something? Or should I try it with another account?
You need to use SSL / OAuth for outgoing mail and Google has this page about how to set things up. They also have a page about problems sending mail that explains that you need SSL (and that links to another page on how to configure an email client).
I don't know about Zend mail, you probably can configure that to use SSL.
精彩评论