Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: Use Email and Name in Mail::to

I have a contact form where someone provides his name and email. I want to send him an email now with Laravel.

I found in the docs

To send a message, use the to method on the Mail facade. The to method accepts an email address, a user instance, or a collection of users.

and in fact

\Mail::to('[email protected]')->send(new \App\Mail\Hello);

works. But is it also possible to provide the name for the email receipt?

I wanted to look that up in the Laravel API for the Mail Facade but to my surprise the facade has no to function?

So how can I find out what the to function really does and if I can pass a name parameter as well?

like image 255
Adam Avatar asked Dec 20 '17 11:12

Adam


1 Answers

In laravel 5.6, answer to your question is: use associative array for every recpient with 'email' and 'name' keys, should work with $to, $cc, $bcc

$to = [
    [
        'email' => $email, 
        'name' => $name,
    ]
];
\Mail::to($to)->send(new \App\Mail\Hello);
like image 182
plus5volt Avatar answered Sep 25 '22 09:09

plus5volt