Laravel 8 Send Mail Using Queue

In this article, we will see laravel 8 send mail using the queue. Sometimes we can see some processes take more time to load like email send, upload CSV file, cron job, etc. Laravel allows you to easily create queued jobs that may be processed in the background. Laravel's queue configuration options are stored in your application's config/queue.php configuration file.

We will learn how to send mail using queue in laravel 8. You can also learn how to send mail in laravel 8 using queue with mailtrap.

So, let's see, send mail using queue in laravel 8.

Step 1: Install Laravel 8

In this step, we will install the laravel application using the below composer command.

composer create-project laravel/laravel example-app



Step 2: Create Mailable Class

Create mail file SendEmailDemo using the below command.

php artisan make:mail SendEmailDemo

You can find the SendEmailDemo.php file in the app/Mail/ folder. And this file should look like this.



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('Test Mail using Queue in Larvel 8')            

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 Mail Using Queue In Laravel 8 - Techsolutionstuff</title>
<h2 style="padding: 23px;border: 6px red solid;">
	<a href="">How To Send Mail Using Queue In Laravel 8 - Techsolutionstuff</a>
<p>This is test mail. This mail send using queue listen in laravel 8.</p>  
<strong>Thanks & Regards.</strong>


Now, we will configure the .env file.



Step 3: Configuration of Queue

Now, we are set up the configuration of the queue driver. So, we will set the 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, migrate the table using the below command.

php artisan migrate



Step 4: Create Queue Job

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

php artisan make:job SendEmailJob

As of now, you can find the app/Jobs/SendEmailJob.php file.


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 the below code in the web.php file.

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



Now, clear the config cache using the below command.

php artisan config:clear

Now, run the laravel application using the below command.

php artisan serve


You might also like:


Techsolutionstuff | The Complete Guide

I'm a software engineer and the founder of Hailing from India, I craft articles, tutorials, tricks, and tips to aid developers. Explore Laravel, PHP, MySQL, jQuery, Bootstrap, Node.js, Vue.js, and AngularJS in our tech stack.