2017-02-22 65 views
0

我使用smtp驅動程序,這是我的代碼在laravel 5.2發送電子郵件:Laravel郵件發送::回報與在Mail ::失敗()沒有具體的誤差零

public function Sendmail() 
{ 
    $data["mail_message"] = "Hello!"; 
    if(Mail::send('Emails.email', $data, function($message) 
    { 
     $message->from('[email protected]', Input::get('name')); 

     $message->to('[email protected]')->subject('Welcome to My Laravel app!'); 
    })) 
    { 
     return "success"; 
    } 
    else 
    { 
     return Mail::failures(); 
    } 
} 

Mail::failures()回報["[email protected]"]與沒有具體的錯誤!

,這是我對mail.php配置:

return [ 

'driver' => env('MAIL_DRIVER', 'smtp'), 
'host' => env('MAIL_HOST', '*******'), 
'port' => env('MAIL_PORT', 587), 
'from' => ['address' => "****@*****", 'name' => "Diling"], 
'encryption' => env('MAIL_ENCRYPTION', ''), 
'username' => env('*****@*****'), 
'password' => env('*************************'), 
'sendmail' => '/usr/sbin/sendmail -bs', 
'pretend' => false, 

]; 

,我使用XAMP現在來測試電子郵件。有什麼想法嗎?

+0

你在你的日誌文件中得到了什麼?他們在這個目錄/ project/storage/logs/ – d1c1pl3

+0

即使我有同樣的問題。在laravel日誌中沒有錯誤,而Mail :: failures()僅僅返回我們發送電子郵件的郵件ID。 –

回答

0

我在使用mail :: send裏面的變量時遇到了麻煩,而且我也不確定mail :: send是否返回布爾值或者類似...我曾經使用過類似於過去寫下的內容。

$nameSend = Input::get('name'); 
    Mail::send('Emails.email', $data, function($message) use ($nameSend){ 
     $message->from('[email protected]', $nameSend); 
     $message->to('[email protected]')->subject('Welcome to My Laravel app!'); 
    }); 

。 。

if(count(Mail::failures()) > 0) { 

    $output = "There was one or more failures. They were: \n"; 

    foreach(Mail::failures as $email_address) { 
    $output = $output. $email_address ."\n"; 
    } 
return $output; 
} 
return "Success!"; 
+0

我不認爲問題是與輸入類型!事實上'Mail :: send'應該在發送成功時發送1,如果發送失敗則發送0。在我的情況下,它會返回0,併爲你的代碼返回'Mail :: failures()',它會返回:'有一個或多個失敗。他們是:amirhasan.hesam @ gmail.com'其實我真的需要知道它爲什麼失敗! –

+0

你檢查過laravel日誌嗎?有時電子郵件發送失敗,並且因爲連接到smtp的錯誤 –

相關問題