PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, November 8, 2022

[FIXED] How to send emails to multiple users using Laravel 7 Mail?

 November 08, 2022     email, html, laravel, laravel-mail, php     No comments   

Issue

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('iamlegend707083@gmail.com')->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?


Solution

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


Answered By - Met Br
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing