SMTP服务器问题swift邮件程序

时间:2016-05-05 05:52:30

标签: yii2

我正在使用yii2框架工作,我正在我的web.php文件中实现swift邮件。它工作正常。

我的配置代码:

    'mailer' => [
         'class' => 'yii\swiftmailer\Mailer',
         'useFileTransport'=>false,
         'transport' => [
             'class' => 'Swift_SmtpTransport',
   ``          'host' => 'smtp.gmail.com',
             'username' => 'testdemomail32@gmail.com',
             'password' => 'TECHEDGE',
             'port' => '465',
             'encryption' => 'ssl',
         ],
     ],

但是当我在服务器端实现同样的事情时,我遇到了问题,我在下面得到了回复:

预期的响应代码250,但得到代码" 535",带有消息" 535-5.7.8不接受用户名和密码。了解更多信息 535 5.7.8 https://support.google.com/mail/answer/14257 k8sm2888892qke.45 - gsmtp

任何帮助谢谢..

1 个答案:

答案 0 :(得分:0)

配置swift邮件程序如下:

 'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'viewPath' => '@common/mail',
           'useFileTransport' => false,//set this property to false to send mails to real email addresses
        //comment the following array to send mail using php's mail function
        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'smtp.gmail.com',
            'username' => 'testdemomail32@gmail.com',
            'password' => 'TECHEDGE',
            'port' => '587',
            'encryption' => 'tls',
                        ],
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
        ],

转到https://www.google.com/settings/security/lesssecureapps并为不太安全的应用启用Access