正在使用yii2,我已经设置了一个邮件程序,如下所示

  <?php
  return [
   'components' => [
  ....
    'mailer' => [
        'class' => 'yii\swiftmailer\Mailer',
        'viewPath' => '@common/mail',
        // 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.
        'useFileTransport' => false,
        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'smtp.gmail.com',
            'username' => '[email protected]',
            'password' => 'mygmailpassword',
            'port' => '465',
            'encryption' => 'ssl',
        ],
    ],
],

](二)
上面的方法在localhost中运行得很好,但是当我上传到live服务器时失败了,我总是得到一个错误的凭据
错误是
Swift_TransportException

 Expected response code 250 but got code "535", with message "535-5.7.8
Username and Password not accepted. Learn more at

535 5.7.8 https://support.google.com/mail/?p=BadCredentials
r199sm3707144wme.1 - gsmtp

“。”
可能是什么问题,

最佳答案

我用这个配置gmail(和工作)

        'transport' => [
            'class' => 'Swift_SmtpTransport',
            'host' => 'smtp.gmail.com',
            'username' => '[email protected]',
            'password' => 'mypass',
            'port' => '587',
            'encryption' => 'tls',
        ],

09-27 07:45