How to send Email to Multiple users |
How to send Email to Multiple users |

How to send Email to Multiple users


Sending emails in Laravel is a common requirement, especially when you need to notify users or send updates. In this tutorial, we will explore how to send Email to Multiple users. We’ll use Laravel’s built-in email functionality along with Eloquent, the ORM (Object-Relational Mapping) included in Laravel.


  1. Basic knowledge of Laravel.
  2. A Laravel project set up with a functioning database.

Step 1:

Set Up Email Configuration First, ensure that your email configuration is set up correctly in the .env file. Open the file and fill in the following details:


Replace your_smtp_host, your_smtp_port,, and your_email_password with your actual SMTP server details.

Step 2:

Create a Mailable Create a new Mailable by running the following Artisan command in your terminal:

php artisan make:mail DatabaseEmail

This will generate a new Mailable class in the app/Mail directory.

Step 3

: Customize the Mailable Open the DatabaseEmail.php file in the app/Mail directory and customize the build method to define the email content. For example:

public function build()
    return $this->view('emails.database')
                ->subject('Email Subject')
                ->with(['data' => $this->data]);

Step 4:

Create Email Blade View Create a new Blade view file named database.blade.php in the resources/views/emails directory. Customize this file to display the data you want in your email.

Step 5: Fetch Data from the Database In your controller or wherever you want to trigger the email, fetch the data from the database using Eloquent:

$data = YourModel::all();

Step 6:

Send Emails Now, loop through the data and send emails using the Mailable you created:

use App\Mail\DatabaseEmail;
use Illuminate\Support\Facades\Mail;

foreach ($data as $item) {
    Mail::to($item->email)->send(new DatabaseEmail($item));

Make sure to replace YourModel with your actual Eloquent model, and adjust the email field ($item->email) based on your database structure.


Congratulations! You have successfully set up a system to send Email to Multiple users database. This step-by-step guide should help you understand the process, and you can customize it further based on your specific needs.

Leave a Reply