考慮採用一組地址並使用郵件功能向每個人發送電子郵件的代碼示例。Laravel 5.4 Mailables將電子郵件地址添加在一起
//In my controller
$email = new EmailToWinners($sender_name, $letter);
foreach ($recipients as $recipient){
Mail::to($recipient)->send($email);
}
//In my App\Mail\EmailToWinner
public function build()
{
return $this->view('emails.winner-email');
}
這些電子郵件都發送得很好,但是當我測試這個時,我注意到了,它將電子郵件堆疊起來。
所以我在日誌中得到這個。
[2017-02-16 15:58:59] local.DEBUG: Message-ID: <[email protected]>
Date: Thu, 16 Feb 2017 15:58:59 +0000
Subject: Email To Winner
From: Example Dev <[email protected]>
To: [email protected]
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
[2017-02-16 15:58:59] local.DEBUG: Message-ID: <[email protected]>
Date: Thu, 16 Feb 2017 15:58:59 +0000
Subject: Email To Winner
From: Example Dev <[email protected]>
To: [email protected], [email protected]
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
[2017-02-16 15:58:59] local.DEBUG: Message-ID: <[email protected]>
Date: Thu, 16 Feb 2017 15:58:59 +0000
Subject: Email To Winner
From: Example Dev <[email protected]>
To: [email protected], [email protected], [email protected]
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
如果你看看電子郵件。第一封電子郵件顯示了 [email protected]
第二個節目,以 [email protected],[email protected]
第三個節目[email protected],[email protected], [email protected]
所以第一個人得到3封電子郵件。
我在做什麼錯?
您對「堆疊電子郵件」意味着什麼up'? – Jerodev
查看日誌中的電子郵件標題。 – ahackney
再次查看你的代碼,應該真的是關於這個問題,你只創建郵件對象一次,然後將郵件發送給用戶,然後再添加'to',另一個'to',等等,因爲它始終是相同的對象,這就是爲什麼你需要在'foreach'中生成它,就像我的評論中提供的那樣,那麼它應該可以工作 – nameless