Reputation: 109
This is my code which sends an email to a single address:
Route::get('/send-mail', function () {
$details = [
'title' => 'Mail From KN7',
'body' => 'Email test in Laravel SMTP'
];
\Mail::to('[email protected]')->send(new \App\Mail\TestMail($details));
echo "Email has been Sent!";
});
Is there any way to change this code so I can send the same email to multiple email addresses?
Upvotes: 0
Views: 4382
Reputation: 63
You can use the array variables for multiple email IDs
Route::get('/send-mail', function () {
$details = [
'title' => 'Mail From KN7',
'body' => 'Email test in Laravel SMTP'
];
\Mail::to(['[email protected]','[email protected]','[email protected]'])->cc(['[email protected]','[email protected]'])->send(new \App\Mail\TestMail($details));
echo "Email has been Sent!";
});
Upvotes: 1
Reputation: 649
You can add simple array :
$usersArray = ['[email protected]', '[email protected]', '[email protected]'];
foreach($usersArray as $user){
\Mail::to($user)->send(new \App\Mail\TestMail($details));
echo "Email has been Sent!";
});
}
Upvotes: 1