Laravel 10 Send Mail using Queue Tutorial

Laravel 10 Send Mail using Queue Tutorial

In this post we will give you information about Laravel 10 Send Mail using Queue Tutorial. Hear we will give you detail about Laravel 10 Send Mail using Queue Tutorial And how to use it also give you demo for it if it is necessary.

What is Queue in Laravel?

Laravel 10 Queues allow you to delay a time-consuming task until a later time. By delaying the time-consuming task, you can improve the performance of the Laravel application significantly.

In this tutorial, we will see how we can send emails using queue in laravel 10. Sometimes sending emails to multiple users may take time. so to overcome this we can push emails in queue. A queue will send emails in the background without delaying the response time.

Sometimes, the Mail send process takes some time. And you don’t want to wait to send an email or another process on loading the server-side process. So, you can use the queue job for sending mail in laravel 10 app. So, This laravel 10 send email using queue example tutorial will create a simple and easy queue job with database driver for test email sending.

So let’s see send mail using queue in laravel 10 and laravel 10 mail queue example.

See also  How to Create Widgets in Laravel?

Step 1: Install Laravel Project

First, open Terminal and run the following command to create a fresh laravel project:

#! /bin/bash
composer create-project --prefer-dist laravel/laravel laravel-mail-queue

or, if you have installed the Laravel Installer as a global composer dependency:

#! /bin/bash
laravel new laravel-mail-queue

Step 2. Configuration SMTP &  Database

You need to configure SMTP details in the .env file like the following:



Step 3. Create Mail Setup

Run the following command:

#! /bin/bash
php artisan make:mail TestMail

Now you will have a new folder Mail in the app directory with the TestMail.php file. So let’s copy the below code and paste into that file.

Also see: How to Install Git On Ubuntu 20.04


namespace AppMail;

use IlluminateBusQueueable;
use IlluminateContractsQueueShouldQueue;
use IlluminateMailMailable;
use IlluminateQueueSerializesModels;

class TestMail 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->view('emails.testMail');

Now we require to create an email view using a blade file. So we will create a simple view file and copy the below code into that blade file.

<!DOCTYPE html>
    <title>Laravel 10 Send Mail using Queue Tutorial - onlinecode</title>
    <p>This is test queue mail.</p>
    <strong>Thank you</strong>

Also see: Laravel 10 Import Export Excel & CSV File Example

See also  How to remove a HTML data attribute in JavaScript

Step 4. Queue Configuration

In this step, configuration on queue driver. So open the .env file and define the database queue driver into the .env file:


We need to generate migration and create tables for a queue. Run the following command:

#! /bin/bash
php artisan queue:table

Now, run the migration command in your terminal.

#! /bin/bash
php artisan migrate

Step 5. Create Queue Job

Now we will create a queue job by the following command. This command will create a queue job file with Queueable. So let’s run the below command:

#! /bin/bash
php artisan make:job TestEmailJob

Now you have the TestEmailJob.php file in the “Jobs” directory. So let’s see that file and put the below code into that file.


namespace AppJobs;

use IlluminateBusQueueable;
use IlluminateContractsQueueShouldQueue;
use IlluminateFoundationBusDispatchable;
use IlluminateQueueInteractsWithQueue;
use IlluminateQueueSerializesModels;
use AppMailTestMail;
use Mail;

class TestEmailJob implements ShouldQueue
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $details;

     * Create a new job instance.
     * @return void
    public function __construct($details)
        $this->details = $details;

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

Also see: Laravel 10 Server Side Datatables Tutorial

Step 6. Create Route

Now it’s time to test created queue job, so let’s create a route with the following code for a testing created queue.

See also  JavaScript − Counting occurrences of a string in string
Route::get('send-email-queue', function(){
    $details['email'] = '<EMAIL ADDRESS>';
    dispatch(new AppJobsTestEmailJob($details));
    return response()->json(['message'=>'Mail Send Successfully!!']);

Step 7. Test Queue Jobs

Now you can watch your queue process using the laravel queue command. Run the following command:

#! /bin/bash
php artisan queue:listen

You can also clear config cache using below command:

#! /bin/bash
php artisan config:clear

Now we can run Laravel, run the following command:

#! /bin/bash
php artisan serve

Now run your project and open the below link:


Thank you for reading this blog.

Also see: How to Clear Cache In Laravel 10

  .       .

If you have any queries or doubts about this topic please feel free to contact us. We will try to reach you.


Hope this code and post will helped you for implement Laravel 10 Send Mail using Queue Tutorial. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US