Kundan Nasir
Kundan Nasir

Reputation: 109

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

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

Answers (2)

Nimal
Nimal

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

Met Br
Met Br

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

Related Questions