通过Gmail smtp服务器与Zend_Mail发送邮件

问题描述:

我希望使用 Gmail smtp服务器通过 Zend_Mail 发送电子邮件。我有这样的代码

I'd like to use Gmail smtp server to send email with Zend_Mail. I had this code

Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Smtp("smtp.googlemail.com", array(
    "auth" => "login",
    "username" => "myusername@gmail.com",
    "password" => "mypassword",
    "ssl" => "ssl",
    "port" => 465
)));

但是当我尝试发送一封电子邮件时,它会抛出一个带有拒绝连接

but when I try to send an email it throws an Exception with message Connection refused.

我在哪里弄错了?

Where I'm wrong?

params是错误的。给它一个这样的镜头:

Your params are wrong. Give it a shot with these:

$config = array(
    'ssl' => 'tls',
    'port' => 587,
    'auth' => 'login',
    'username' => 'myusername@gmail.com',
    'password' => 'mypassword'
);
$transport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
Zend_Mail::setDefaultTransport($transport);