Reputation: 318
I'm using Laravel 4 , tying to send mail to multiple user using Queueing Mail , my code looks like -
$mailuserlist=DB::table('table')
->join('some_table')
->select('some_thing')
->where('somecondition'))->get();
Mail::queue('mail_template', $data, function($message) use ($mailuserlist)
{
$message->from('[email protected]', 'Mail Notification');
foreach ($mailuserlist as $value) {
$message->to($value['email'],$value['firstname'].' '.$value['lastname']);
}
$message->subject('Testing mail');
});
..it's not at all working . How can i send ail to multiple address ??
Upvotes: 2
Views: 8928
Reputation: 255
**
**
$users = UsersGroup::where(['groups_id' => $group->id])->get();
if(!$users->count()) {
Mail::send('emails.groups.delete-group', [
'group' => $group->title,
], function ($message) use ($group, $users) {
$message->from(Config::get('mail.from.address'), Config::get('mail.from.name'))
->subject(Lang::get('groups.group_deleted'));
foreach ($users as $user) {
$message = $message->to($user->users->email);
}
});
}
Upvotes: 0
Reputation: 466
You can get all emails to send
$users = User::select('email')->get()->toArray();
And delete the key of array for get an array only with the emails
$emails = array_pluck($users, 'email');
And then run the Mail::queue
Mail::queue('mail.your_view', [], function($message) use ($emails) {
$message->from('[email protected]', 'Mail Notification');
$message->to($emails);
$message->subject('Your Subject');
});
Upvotes: 0
Reputation: 7277
It should be possible in two ways as we can see in the source code framework/src/Illuminate/Mail/Message.php:
Chaining:
->to($address1, $name1)->to($address2, $name2)->to($address3, $name3)...
Using array of addresses:
->to(array($address1,$address2,$address3,...), array($name1,$name2,$name3,...))
Upvotes: 6
Reputation: 7863
Queueing Mail doesn't seem to support sending 1 mail to multiple user. I think you should queue 1 mail for each of your recipients:
$mailuserlist=DB::table('table')
->join('some_table')
->select('some_thing')
->where('somecondition'))->get();
foreach ($mailuserlist as $mailuser) {
Mail::queue('mail_template', $data, function($message) use ($mailuser) {
$message
->from('[email protected]', 'Mail Notification')
->to($mailuser['email'],
$mailuser['firstname'].' '.$mailuser['lastname'])
->subject('Testing mail');
});
}
Upvotes: 4