Send mail to multiple addresses in Laravel

If you want to send same mail to multiple addresses, you have to use an array or a loop.

$emails = array("myemail1@email.com", "myemail2@email.com");

$input = Input::all();

 

Mail::send('emails.admin-company', array('body' => Input::get('email_body')),

    function($message) use ($emails, $input) {

        $message

        ->from('admin@admin.org', 'Administrator')

        ->subject('Admin Subject');

 

        $message->to($emails);

});

Don’t forget to enable your IP to relay email outside of your domain. When you have to send mail to multiple addresses, first check if it's working with one mail Id then do what you want.

The mailable tries to access ->email and it will result in ErrorException in Mailable.php , so this solution will not work in Laravel 5.3.

For Laravel5.3

$users_temp = explode(',', 'first@example.com,second@example.com');

    $users = [];

    foreach($users_temp as $key => $ut){

      $ua = [];

      $ua['email'] = $ut;

      $ua['name'] = 'test';

      $users[$key] = (object)$ua;

    }

 Mail::to($users)->send(new OrderAdminSendInvoice($o));