Reputation: 63
I have an array of recipients $this->recipients
and I want to send an email to all recipients without showing each other emails.
Currently, it shows all the recipients in an email.
if (count($this->recipients) > 1) {
Mail::bcc($this->recipients)
->send(new EmailNotificationMailable($this->notificationRequest));
} else {
Mail::to($this->recipients)
->send(new EmailNotificationMailable($this->notificationRequest));
}
I tried this code but when I send with Mail::bcc
the To
of email is empty.
Please give the working solution for this. I don't want to loop recipients array
Upvotes: 0
Views: 560
Reputation: 42
You need to loop through the recipients collection:
if(count($this->recipients) > 1)
{
$this->recipients->each(function($recipient)
{
Mail::to(recipient)->bcc($this->recipients)->send(new EmailNotificationMailable($this->notificationRequest));
}
}else{
Mail::to($this->recipients)->send(new EmailNotificationMailable($this->notificationRequest));
}
Upvotes: 1
Reputation: 1639
Use something like this:
Mail::to(array_pop($this->recipients))->bcc($this->recipients)
This will set the last entry in the recipients
array as the mail receiver and every other addresses will be included via BCC.
Upvotes: 0