Laravel Mail::Send() Sending to Multiple to or Bcc Addresses

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

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) .

How to send emails to multiple users using Laravel 7 Mail?

You can add simple array :

 $usersArray = ['mail@gmail.com', 'mail2@gmail.com', 'mail3@gmail.com'];

foreach($usersArray as $user){

\Mail::to($user)->send(new \App\Mail\TestMail($details));
echo "Email has been Sent!";
});
}

Sending email to multiple recipients using Laravel

are you using queue jobs? you must use it otherwise your server may not respond for multiple email. second you are sending multiple emails at the same time may be you should try this.

$mails = User::select('users.name','users.staffid','users.email')->get();

foreach($mails as $dat)
{

Mail::send('email.sendReminder', ["data1"=>$dat], function($message) use ($dat) {
$message->from('test@gmail.com', 'Test Reminder');
$message->to($dat['email']);
$message->subject('Reminder');
});

}

Sending email to multiple cc recipients in Laravel 5.4

The setAdress() function in Mailable allow you to give an array as argument:

Mailable.php

So You should be able to use the function by passing an array as your argument

Mail::to($email)
->cc(['name1@example.com','name2@example.com'])
->send(new document());

How to send Multiple mail Using laravel?

You can use mailable and send mail to multiple recipients adding them in the loop. You can refer more in the documentation link.

https://laravel.com/docs/8.x/mail

foreach (['taylor@example.com', 'dries@example.com'] as $recipient) {
Mail::to($recipient)->send(new OrderShipped($order));
}

Laravel 5.3 send Mail to multiple email-adresses

I think it should work, when you pass an array. Check the reference:

https://laravel.com/api/5.3/Illuminate/Mail/Message.html#method_to

The first parameter can be an array. Try it.



Related Topics



Leave a reply



Submit