2017-03-06 150 views
2

發送問題我想發送使用laravel 5.4的電子郵件。這裏是我的.ENV郵件laravel 5.4

MAIL_DRIVER=smtp 
MAIL_HOST=smtp.gmail.com 
MAIL_PORT=587 
[email protected] 
MAIL_PASSWORD=password 
MAIL_ENCRYPTION=tls 

這裏是我的的HomeController

<?php 

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 
use App\Http\Requests; 
use Mail; 
use App\Mail\MyTestMail; 

class HomeController extends Controller 
{ 

    /** 
    * Send My Test Mail Example 
    * 
    * @return void 
    */ 
    public function myTestMail() 
    { 
     //echo 'hello'; 
     $myEmail = '[email protected]'; 
     Mail::to($myEmail)->send(new MyTestMail()); 


     dd("Mail Send Successfully"); 
    } 

} 

但我

Swift_TransportException在AbstractSmtpTransport.php線383得到了一個錯誤,如

: 期望的迴應代碼250但獲得代碼「535」,並帶有消息「535-5.7.8 Usernam e和密碼不被接受。瞭解更多535 5.7.8 https://support.google.com/mail/?p=BadCredentials r67sm38867592pfb.125 - gsmtp「

at Swift_Transport_AbstractSmtpTransport->_assertResponseCode('535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials r67sm38867592pfb.125 - gsmtp ', array(250)) in AbstractSmtpTransport.php line 281 
at Swift_Transport_AbstractSmtpTransport->executeCommand('RSET ', array(250), array()) in EsmtpTransport.php line 270 
at Swift_Transport_EsmtpTransport->executeCommand('RSET ', array(250)) in XOAuth2Authenticator.php line 55 
at Swift_Transport_Esmtp_Auth_XOAuth2Authenticator->authenticate(object(Swift_SmtpTransport), '[email protected]', 'password') in AuthHandler.php line 176 
at Swift_Transport_Esmtp_AuthHandler->afterEhlo(object(Swift_SmtpTransport)) in EsmtpTransport.php line 332 

然後,我改變我的.ENV文件

MAIL_DRIVER=smtp 
MAIL_HOST=smtp.gmail.com 
MAIL_PORT=587 
[email protected] 
MAIL_PASSWORD=password2 
MAIL_ENCRYPTION=tls 

然後我重新啓動apache2.But仍然是相同的與以前的用戶名和password.i錯誤不知道爲什麼會這樣?請幫助我。

+0

我對與PHP7 L5.4同樣的問題。但我嘗試在本地php54能發送出相同的設置。我正在努力弄清楚造成的原因。 –

回答

2

谷歌目前並沒有從安全性較低的應用程序

01接受登錄

您需要授權的外部應用程序使用的Gmail。

執行以下步驟,並授權使其:

首先,去your Google Account Management page

下的安全性選項,單擊授權 應用&網站

的編輯鏈接或

可以允許不夠安全的應用你在Gmail設置,請訪問:

https://www.google.com/settings/security/lesssecureapps

,並設置 '不夠安全的應用訪問' 爲 「Enabled」

希望它可以幫助你。

+0

感謝@valnoc thankyew非常.. –

+0

@Shanukk歡迎您:) – vanloc