Send mail with Zend_Mail through Gmail smtp server

2019-06-26 00:57发布

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?

1条回答
Explosion°爆炸
2楼-- · 2019-06-26 01:35

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);
查看更多
登录 后发表回答