Send Mail using Gmail SMTP Server Laravel 8 Example.




Send Mail using Gmail SMTP Server Laravel 8 Example.

Hi Friends,

It's simple example of laravel 8 sending mail gmail.

We will look at example of laravel 8 send email using google gmail. This post will give you simple example of gmail smtp send email in laravel 8.

I am going to show you example of laravel 8 send mail using gmail smtp.

You can create blade file design and also with dynamic information for mail layout.

In this tutorial, i will give you step by step instruction to send email using google gmail smtp server in laravel 8.

Let's start to example.

Step 1 : Add Configuration

You add send mail configuration with mail driver as gmail server, mail host, mail port, mail username, mail password so laravel 8 will use sender details on email.







First You have to enable google security setting form your gmail.

Second go to Google account and click on ‘Account’. Once you are on the ‘Account’ page, click on ‘Security’. Scroll down to the bottom and you will find ‘Less secure app access’ settings. Set as ON.

Step 2 : Create Mail

In this step we will create mail class MyDemoMail for email sending. Here we will write code for which view will call and object of user. So let's run bellow command.

php artisan make:mail MyDemoMail



namespace App\Mail;

use Illuminate\Bus\Queueable;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Mail\Mailable;

use Illuminate\Queue\SerializesModels;

class MyDemoMail extends Mailable


use Queueable, SerializesModels;

public $details;


* Create a new message instance.


* @return void


public function __construct($details)


$this->details = $details;



* Build the message.


* @return $this


public function build()


return $this->subject('Mail from')




Step 3 : Create View Blade

In this step, we will create blade view file and write email that we want to send.

Now we just write some dummy text. create bellow files on "emails" folder.


<!DOCTYPE html>






<h1>{{ $details['title'] }}</h1>

<p>{{ $details['body'] }}</p>

<p>Thank you</p>



Step 4 : Add Route

Now at last we will create "MyDemoMail" for sending our test email. so let's create bellow web route for testing send email.


Route::get('send-mail', function () {

$details = [

'title' => 'Mail from',

'body' => 'This is a test email using SMTP'


\Mail::to('')->send(new \App\Mail\MyDemoMail($details));

dd("Mail Sent Successfully.");


Run Your Project:

php artisan serve


#Laravel 8