Laravel Mail::send() sending to multiple to or bcc addresses

laravel send mail to multiple recipients from database
laravel send bulk email
laravel send email with attachment
laravel mail log
laravel mail carbon copy
laravel mail from name
laravel mail::send response
send email laravel free

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 specify one recipient.

I've tried chaining:

// for example
$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');

        foreach ($emails as $email) {
            $message->to($email);
        }
});

and passing an array:

// for example
$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);
});

but neither seem to work and I get failure messages when returning Mail::failures(), a var_dump() of Mail::failures() shows the email addresses that I tried to send to, for example:

array(2) {
  [0]=>
  string(18) "myemail1@email.com"
  [1]=>
  string(18) "myemail2@email.com"
}

Clearly doing something wrong, would appreciate any help as I'm not understanding the API either: http://laravel.com/api/4.2/Illuminate/Mail/Message.html#method_to

I realise I could put the Mail::send() method in a for/foreach loop and Mail::send() for each email address, but this doesn't appear to me to be the optimal solution, I was hoping I would also be able to ->bcc() to all addresses once everything was working so the recipients wouldn't see who else the mail is being sent to.

I've tested it using the following code:

$emails = ['myoneemail@esomething.com', 'myother@esomething.com','myother2@esomething.com'];

Mail::send('emails.welcome', [], function($message) use ($emails)
{    
    $message->to($emails)->subject('This is test e-mail');    
});
var_dump( Mail:: failures());
exit;

Result - empty array for failures.

But of course you need to configure your app/config/mail.php properly. So first make sure you can send e-mail just to one user and then test your code with many users.

Moreover using this simple code none of my e-mails were delivered to free mail accounts, I got only emails to inboxes that I have on my paid hosting accounts, so probably they were caught by some filters (it's maybe simple topic/content issue but I mentioned it just in case you haven't received some of e-mails) .

php, 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 specify one  Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.Provide details and share your research! But avoid …. Asking for help, clarification, or responding to other answers.

If you want to send emails simultaneously to all the admins, you can do something like this:

In your .env file add all the emails as comma separated values:

ADMIN_EMAILS=admin1@site.com,admin2@site.com,admin3@site.com

so when you going to send the email just do this (yes! the 'to' method of message builder instance accepts an array):

So,

$to = explode(',', env('ADMIN_EMAILS'));

and...

$message->to($to);

will now send the mail to all the admins.

Laravel Mail::send() sending to multiple to or bcc , 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 specify one  Laravel Mail::send() sending to multiple to or bcc addresses 0 How can I dinamically pass the recipient e-mail address into the Mail::send() inner callback function?

the accepted answer does not work any longer with laravel 5.3 because mailable tries to access ->email and results in

ErrorException in Mailable.php line 376: Trying to get property of non-object

a working code for laravel 5.3 is this:

$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));

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. Mail::send('emails.admin-company', array('body'  From the Laravel 5.4 documentation on Sending Mail: The to method accepts an email address, a user instance, or a collection of users. If you pass an object or collection of objects, the mailer will automatically use their email and name properties when setting the email recipients, so make sure these attributes are available on your objects.

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.

Sending Emails with multiple bcc, When sending an email with an array of bcc's, how can I access the current bcc Mail::bcc($emails)->send(new SomeClass($var1, $var2));. The only problem here is that if there were 50 different users, it would send out 50 emails. I could always add the other emails to the bcc field, but I don't know if that would be the correct way of doing it. I basically want to send out batch emails everytime someone submits a new post. Any insight on the best approach for this would be

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");
        });

How do I send email to multiple recipients from a single email form?, I am using Laravel 5.4. Using JavaScript, the email recipients input box is populated and However, if the input box has just one recipient the email is sent and the mail to the Enrollee Mail::send(new emailToEnrollee($event)); } } The mail to() function can then take this array of emails and dispatch. I am using the default Laravel Mail class to send emails. I am trying to add bcc to myself, but when I add a bcc the email is not send at all. Here is my code: Mail::send( 'emails.order.order

Mail facade - Mail - Laravel, In Laravel, each type of email sent by your application is represented as a "​mailable" class. Instead, you may specify a global "from" address in your config​/mail.php @component('mail::message') # Order Shipped Your order has been shipped! You may add as many button components to a message as you wish: This will then replicate the behaviour of a Bcc. Go to Settings > Sending Defaults. Check or uncheck the box labeled Expose The List Of Recipients When Sending To Multiple Addresses. If checked, when you send to multiple recipients, they will be able to see each other's email addresses (useful for Reply All).

Laravel Mail::send() sending to multiple to or bcc , 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  Bcc stands for blind carbon copy. This field hides the email addresses entered in it. Only the original sender of the email can view the Bcc recipients. So, to keep maximum anonymity, put your email address in the To field and use Bcc for recipients.

Laravel send mail to multiple recipients with the “Name” of recipient , How to hide multiple recipient email addresses laravel send mail. i use laravel Mail function to send html mail to multiple email i create array of emails the message sent Mail::to($request->user()) ->cc($moreUsers) ->bcc($​evenMoreUsers) ->send(new OrderShipped($order)); And the bcc() part will hide the recipients  This is where the “Bcc” (Blind Carbon Copy) field and a contact named “Undisclosed Recipients” come in. Using the Bcc Field. When you put an address in the “Bcc” field, no recipient of the message can see that address. The “Bcc” field is useful in different circumstances: If you’d like to send a blind copy of a message to

Comments
  • Show more code. Have you tried to insert there existing emails. What failure messages you get?
  • What do you mean by existing emails? I am sending it to valid email addresses if that's what you mean? Will add more code with the failure messages. Thanks.
  • Thanks for your reply. Apparently I wasn't doing anything wrong, but my IP at work wasn't enabled to relay email outside of our domain! All sorted and working now. Thanks again.
  • @haakym That's why if something doesn't work, you should always try to use the simplest code and make sure it works without a problem. Often problems are not where you expect them to be.
  • If i want to write somewhere the name of the receipts, how i can do this?
  • this does not work any longer with laravel 5.3 because mailable tries to access ->email and results in ErrorException in Mailable.php line 376: Trying to get property of non-object a working code for laravel 5.3 is ... i actually will create my answer because it looks messy here. But feel free to add my answer to your accepted answer. My answer: stackoverflow.com/a/39734742/533426
  • Tested in Laravel 5.6, all working. However the array needs to be created, if you are pulling emails data from another table, run a foreach and array_push to a new array.
  • Best answer for usage of .env file
  • You shouldn't reference the ENV directly - use the config helper.
  • Thank you for this answer. Saved me a lot of time and grief. Is this change intentional because it seems like too much code for something that should be very short hand. I am defining my to() function using a variable $to = [(object) ['name' => 'Example Name', 'email' => 'test@example.com'], (object) ['name' => 'Example Name 2', 'email' => 'test2@example.com']];
  • How I can use $message->to($emails); but include the name of the recipents?
  • @JCarlos have the email be the key of the associative array, ['email@email.com' => 'Joe', 'email2@email.com' => 'Jack']
  • Instead of creating an array element you can just have it as Contacts::pluck('email')->toArray()
  • This would send N emails to N recipients. The goal is to send 1 email to N recipients.
  • ^ for that, use what @Grant mentioned on an answer below, an associative array ['email@email.com' => 'Joe', 'email2@email.com' => 'Jack'].