Are you looking for example of laravel 8 send mail using queue. In this article, we will implement a laravel 8 send mail in queue. This post will give you simple example of laravel 8 send email with queue. Here you will learn laravel 8 queue mail send. Alright, let’s dive into the steps.

Sometime, you see some process take time to load like email send, payment gateway etc. When you send email for verification or send invoice then it load time to send mail because it is services. If you don’t want to wait to user for send email or other process on loading server side process then you can use queue. because it’s very fast and visitor will happy to see loading time.

Here, i am going to share very simple example to create queue with database driver for test email sending. You can definitely understand how to work queue and how it’s easy. If you haven’t used before then don’t worry, here if from starch and very simple.

Step 1: Setup Laravel 8

first of all we need to get fresh Laravel 8 version application using bellow command, So open your terminal OR command prompt and run bellow command:

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

Step 2: Create Mail Setup

We are going from scratch and in first step, we will create email for testing using Laravel Mail facade. So let’s simple run bellow command.

php artisan make:mail SendEmailTest

Now you will have new folder “Mail” in app directory with SendEmailTest.php file. So let’s simply copy bellow code and past on that file.

app/Mail/SendEmailTest.php

<?php

namespace App\Mail;

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

class SendEmailTest 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.test');
    }
}

Ok, now we require to create email view using blade file. So we will create simple view file and copy bellow code om following path.

resources/views/emails/test.blade.php

<!DOCTYPE html>
<html>
<head>
    <title>How to send mail using queue in Laravel 8? - ItSolutionStuff.com</title>
</head>
<body>

<center>
<h2 style="padding: 23px;background: #b3deb8a1;border-bottom: 6px green solid;">
    <a href="https://itsolutionstuff.com">Visit Our Website : ItSolutionStuff.com</a>
</h2>
</center>

<p>Hi, Sir</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

<strong>Thank you Sir. :)</strong>

</body>
</html>

after configuration of view file, we have to setup for email send, So let’ set configuration in .env file:

.env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=xyz@gmail.com
MAIL_PASSWORD=123456
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=xyz@gmail.com
MAIL_FROM_NAME="${APP_NAME}"

#laravel #php #web-development #programming #developer

Laravel 8 Send Mail using Queue Example
9.15 GEEK