zf2 - gmail smtp不能正常工作

时间:2015-01-19 11:38:11

标签: php email zend-framework2 smtp

我之前发送邮件的smtp设置如下,工作正常。

$options = new Mail\Transport\SmtpOptions(array(
    'name' => 'gmail.com',
    'host' => 'smtp.gmail.com',
    'port' => 465,
    'connection_class' => 'login',
    'connection_config' => array(
        'username' => 'myname@mywebsite.com',
        'password' => 'password',
        'ssl'=> 'ssl',
    ),
));

$transport = new Mail\Transport\Smtp($options);
$transport->send($mail);

但如果我使用其他帐户

$options = new Mail\Transport\SmtpOptions(array(
    'name' => 'gmail.com',
    'host' => 'smtp.gmail.com',
    'port'=> 465,
    'connection_class' => 'login',
    'connection_config' => array(
        'username' => 'mynewname@gmail.com',
        'password' => 'newpassword',
        'ssl'=> 'ssl',
    ),
));

$transport = new Mail\Transport\Smtp($options);
$transport->send($mail);

它给出了如下所示的错误

enter image description here

我做错了什么。请帮忙。我是zend的新手。

1 个答案:

答案 0 :(得分:0)

我创建了一个自动加载文件mail.local.php,其中包含以下内容,它对我有用!

return array(
'smtp' => array(
    'transport' => array(
        'options' => array(
            'host' => 'smtp.gmail.com',
            'connection_class' => 'plain',
            'port' => '587',
            'connection_config' => array(
                'username' => 'my-gmail-email-d',
                'password' => 'my-email-password',
                'ssl' => 'tls'
            ),
        ),
    ),
)    

);

您可以通过将端口从465更改为587并删除'connection_class' => 'login'来查看吗?

相关问题