I can\'t seem to successfully send to multiple addresses when using Laravel\'s Mail::send()
callback, the code does however work when I only sp
This works great - i have access to the request object and the email array
$emails = ['tester@blahdomain.com', 'anotheremail@blahdomian.com'];
Mail::send('emails.lead', ['name' => $name, 'email' => $email, 'phone' => $phone], function ($message) use ($request, $emails)
{
$message->from('no-reply@yourdomain.com', 'Joe Smoe');
// $message->to( $request->input('email') );
$message->to( $emails);
//Add a subject
$message->subject("New Email From Your site");
});
With Laravel 5.6, if you want pass multiple emails with names, you need to pass array of associative arrays. Example pushing multiple recipients into the $to
array:
$to[] = array('email' => $email, 'name' => $name);
Fixed two recipients:
$to = [['email' => 'user.one@example.com', 'name' => 'User One'],
['email' => 'user.two@example.com', 'name' => 'User Two']];
The 'name' key is not mandatory. You can set it to 'name' => NULL
or do not add to the associative array, then only 'email'
will be used.
In a scenario where you intend to push a single email to different recipients at one instance (i.e CC multiple email addresses), the solution below works fine with Laravel 5.4 and above.
Mail::to('dunsin.olubobokun@domain.com')
->cc(['paul.yomi@domain.com','stack.overflow@domain.com','abc.xyz@domain.com','nigeria@domain.com'])
->send(new document());
where document is any class that further customizes your email.
Try this:
$toemail = explode(',', str_replace(' ', '', $request->toemail));