4
votes

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.

3
@Rahul : You were in a hurry to call it a duplicate. My question addresses a different problem.M.J

3 Answers

2
votes

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.

2
votes

This worked for me, with Laravel 5.6:

$to = [
    ['email' => '[email protected]', 'name' => 'Name 1'],
    ['email' => '[email protected]', 'name' => 'Name 2']
];
1
votes

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!');

});