I have this requirement, where I need to send separate mails to all the users in TO and CC header from my application.
So, for example, I add abc@xyz.com in TO; asd@fgh.com in, qwe@rty.com in CC. There are three email-ids here, cumulative of TO and CC.
I need to send a separate mail to all three. So, abc@xyz.com will only see his name in the Mail header, and so on for CC recipients.
My approach was to merge all the emails in an array, and then run a foreach loop, something like this:
foreach($emails as $email) {
Mail::send(.....
{
$message->to($email);
});
}
Is this a better way to do this? Or any other much better approach that I can follow?
if (!empty($users)) {
foreach ($users as $user) {
Mail::send('emails.acitvation', ['item' => $xyz, 'user' => $user],
function ($message) use ($user) {
$message->subject('your subject here');
$message->to($user['email']);
});
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.