How To Send E-mail Using Queue In Laravel 9

Websolutionstuff | Feb-21-2022 | Categories : Laravel PHP

In this tutorial, I will show you how to send e-mail using queue in laravel 9, Some time we can see many processes take more time to load like payment gateway processes, bulk email sending, etc. Whenever you are sending an email for verification then it loads time to send mail because it is services. If you don't want to wait for the user to send an email or other processes on loading server-side process then you can use the queue.

In laravel 9 send mail using queue example we will set up the mailtrap for sending an email. Laravel queues provide a unified queueing API across a variety of different queue backends, such as Amazon SQSRedis, or even a relational database.

So, let's see send mail using queue in laravel 9 and laravel 9 mail queue example.

Step 1 : Install Laravel 9 Application

Step 2 : Create Mail Setup

Step 3 : Configuration of Queue

Step 4 : Create Queue Job

Step 5 : Test Queue Job


Step 1 : Install Laravel 9

First, we need to install the laravel 9 application using the composer command.

composer create-project --prefer-dist laravel/laravel blog



Step 2 : Create Mail Setup

Run the below command in your terminal

php artisan make:mail SendEmailDemo

Now you will find the new Mail folder in the app directory with the SendEmailDemo.php file. So, copy the below code on this file.



namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class SendEmailDemo extends Mailable
    use Queueable, SerializesModels;

     * Create a new message instance.
     * @return void
    public function __construct()

     * Build the message.
     * @return $this
    public function build()
        return $this->subject('How To Send E-mail Using Queue In laravel 9')            

After that, we need to create an email view using a blade file. So, we will create demo.blade.php following the path.




<!DOCTYPE html>
	<title>How To Send E-mail Using Queue In Laravel 9 - Websolutionstuff</title>
	<a href="">Visit Our Website : Websolutionstuff</a>

<p>This is a test mail. This mail send using queue listen in laravel 9.</p>  

<strong>Thanks & Regards.</strong>


Now, we will configure of view file, which we have to set up for email send, So let's configuration in the .env file.




Step 3: Configuration of Queue

Now, we are set up configuration on queue driver so first of all, we will set queue driver "database". You can set it as you want. also, we will define the driver as redis too. so, here define the database driver on the .env file.


After that, we need to generate migration and create tables for queues. So, let's run the below command for queue database tables.

php artisan queue:table

Now, run the migration in your terminal.

php artisan migrate



Step 4: Create Queue Job

In this step, we will create a new queue job. So, copy the below command in your terminal.

php artisan make:job SendEmailJob

As of now, you will find the SendEmailJob.php file in this path app/Jobs/SendEmailJob.php. So, copy the below code to that location.


namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use App\Mail\SendEmailDemo;
use Mail;

class SendEmailJob implements ShouldQueue
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $send_mail;
     * Create a new job instance.
     * @return void
    public function __construct($send_mail)
        $this->send_mail = $send_mail;

     * Execute the job.
     * @return void
    public function handle()
        $email = new SendEmailDemo();        



Step 5: Test Queue Job

Now, we will test our queue job. add below code in your web.php file

Route::get('test/email', function(){
	$send_mail = '[email protected]';
    dispatch(new App\Jobs\SendEmailJob($send_mail));
    dd('send mail successfully !!');

Now, clear config cache using the below command for sending mail with queue laravel 9.

php artisan config:clear

Now, run this laravel 9 queue example with artisan command.

php artisan serve


You might also like :

Recommended Post
Featured Post
Drag and Drop File Upload Using Dropzone js in Laravel 9
Drag and Drop File Upload Usin...

In this article, we will see drag and drop file upload using dropzone js in laravel 9. Dropzone JS is an open-source lib...

Read More


How To Get env Variable In Controller Or Blade File
How To Get env Variable In Con...

In this tutorial, I will give you information on how to get the .env variable in the controller or file. Many times we n...

Read More


Laravel 9 Image Upload Example
Laravel 9 Image Upload Example

In this tutorial, I will explain the laravel 9 image upload example. image or file upload is the most common task in web...

Read More


Datatable Custom Export Button Example
Datatable Custom Export Button...

Hello Guys, In this tutorial we will see how to add datatable custom export button example. datatable provide inbuilt...

Read More