2016-03-10 59 views
1

我與yii2有錯誤,我無法通過yii用電子郵件帳戶發送電子郵件。如果我的密碼是正確的:( 這是我的代碼:yii2中未接受用戶名和密碼

web.php

'mailer' => [ 
      'class' => 'yii\swiftmailer\Mailer', 
      'transport' => [ 
      'class'  => 'Swift_SmtpTransport', 
      'host'  => 'smtp.gmail.com', 
      'username' => '[email protected]', 
      'password' => 'passwd', 
      'port'  => '587', 
      'encryption' => 'tls', 
      ], 
     ], 
     'log' 

Controller.php這樣

Yii::$app -> mailer -> compose() 
      -> setFrom('[email protected]') 
      -> setTo('[email protected]') 
      -> setSubject('Test') 
      -> setTextBody('Plain text content') 
      -> setHtmlBody('It is a test') 
      -> send(); 

This is my error

+1

請將錯誤粘貼到問題中。 – starf

回答

1

它看起來像你正在使用Google SMTP服務器,谷歌有一個新的安全機構ck,只允許您發送來自谷歌應用程序的電子郵件。如果你使用其他任何你會遇到這樣的錯誤。具有

'mailer' => [ 
      'class' => 'yii\swiftmailer\Mailer', 
      'useFileTransport' => false, 
     ], 

我找到了第一個解決方案更有效

更改谷歌設置爲允許安全性較低的應用程序

使用默認的sendmail功能:爲了解決這個問題,你可以做如下

點擊此鏈接更改你的Gmail郵箱設置https://myaccount.google.com/security

0

我用下面的配置和工作的權利

是pratically等於你的,但與別不同的用戶名是谷歌郵件用戶,而不是一個noyt谷歌應用程序的用戶

'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' => true, 
     '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' => '[email protected]', 
      'password' => 'mypassword', 
      'port' => '587', 
      'encryption' => 'tls', 
     ], 
    ], 

希望是有用

相關問題