Reputation: 2991
We can send mails to multiple recipients by passing the array of recipients in the $message->to() function of mail. There is the solution to send the multiple recipients but it does not include names, it just include email id's. Send Mail to Multiple Recipients
But how can I add the names of these recipients which are in array to the mail. For Example: When I send a mail to single recipient then its like where we can pass the second parameter as name of the recipient.
$message->to("[email protected]", "Alex");
But when I send the mail to multiple recipients the its like:
$emails = ['[email protected]', '[email protected]','[email protected]'];
Mail::send('emails.welcome', [], function($message) use ($emails)
{
$message->to($emails)->subject('This is test e-mail');
});
Is there a way that I can add the names of the recipients to this.
Upvotes: 4
Views: 9398
Reputation: 544
This worked for me, with Laravel 5.6:
$to = [
['email' => '[email protected]', 'name' => 'Name 1'],
['email' => '[email protected]', 'name' => 'Name 2']
];
Upvotes: 1
Reputation: 3186
Could you try to send the emails and names as an associative array?
Eg.
$emails = [
'[email protected]'=>'Name',
'[email protected]'=>'Name1',
'[email protected]'=>'Name2
];
I haven't tried this but according to Swift Mailer setTo()
, this can be done.
Hopefully that works.
Upvotes: 2
Reputation: 37
you can use bcc
Mail::send('mail', array('key' => $todos1), function($message) {
$message->to('[email protected]')
->bcc(array('[email protected]','[email protected]','[email protected]','[email protected]'))
->subject('Welcome!');
});
Upvotes: 1