我一直在嘗試使用laravel Mail::send()
函數獲取沒有收到電子郵件的收件人列表。我正在嘗試下面的代碼。 for
循環用作因爲每個用戶都要接收定製的消息。laravel Mail :: failures()函數是如何工作的?
// First recipient is actual, the second is dummy.
$mail_to_users = ["[email protected]","[email protected]"];
$failures = [];
foreach($mail_to_users as $mail_to_user) {
Mail::send('email', [], function($msg) use ($mail_to_user){
$msg->to($mail_to_user);
$msg->subject("Document Shared");
});
if(count(Mail::failures()) > 0) {
$failures[] = Mail::failures()[0];
}
}
print_r($failures);
我一直在嘗試所有可能的選擇。我將config/mail.php
中正確的郵件配置更改爲錯誤的配置。但如果我這樣做,然後laravel顯示錯誤頁面,但$failure
變量總是返回空。
值得什麼,只有非常特殊類型的故障是由Swiftmailer重新調整:幾乎只有在這個意義上失敗的方法用於郵件拒絕了地址/電子郵件。使用'SMTP'這通常是可以的,因爲SMTP服務器會立即返回失敗,但像使用sendmail這樣的東西很少(如果有的話)會返回失敗,因爲電子郵件只是被接受而不管,然後發送。因此,如果您在郵件配置中使用'sendmail'(或者甚至可能是'mail'),則可能需要使用不同的方式來監視傳遞失敗。 – alexrussell
請參閱http://swiftmailer.org/docs/sending.html以獲取何時進行的文檔以及是否返回故障。 – alexrussell