clock  Mon - Sun 8.00 AM - 8.00 PM
play store

How to send mail in Laravel 8

writter  Hariom Prajapati
Date  03 Jul 2022
Language  Laravel
How to send mail in Laravel 8

How to send mail in Laravel 8

In this article we will learn how to send mail in Laravel 8

Follow the below steps to send mail in laravel.


Step 1- Mail Configuration

In step first, we have to set  mail configuration settings with mail driver in  .env file like below example.


[email protected]  #sender email id
[email protected]                   #sender email password
[email protected]
MAIL_FROM_NAME="Teknowize"             #your app name 


Step 2 – Create Male Class

In second step we will create TestMail class  for mail sending. 

Go to your terminal  and simply run this below command.

php artisan make:mail TestMail




Step 3 –Make controller 

Create a new MailController.php controller

php artisan make:controller MailController


app \Http \Controllers\ MailController.php

namespace App\Http\Controllers; 
use App\Mail\TestMail;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail; 
class MailController extends Controller

    function send_mail(){

        $email_id = '[email protected]';
        $msg = [
            'title' => 'Hello! from Teknowize',
            'body' => 'This is my test mail in Laravel 8'
        Mail::to($email_id)->send(new TestMail($msg));
        return' Mail send successfuly to '.$email_id ; 


Step 4 – Create Route


use App\Http\Controllers\MailController;
use Illuminate\Support\Facades\Route;
| Web Routes
Route::get('send_mail', [MailController::class, 'send_mail']);



Step 5 – Create message template 

In this step, open your resources/views folder then create a Email folder then create mail.blade.php in  Email folder.

You can also create blade page in resources/views without making any folder.


resources \views \Email \mail.blade.php

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
<h1>{{ $msg['title'] }}</h1>
    <p>{{ $msg['body'] }}</p>
    <a href=""><button style="background:blue;color:whitesmoke">Learn More</button></a>
    <p>Thank you!</p> 


Step 6- Go to gmail account security then click on the less secure app access setting. If this  is On then skip this step otherwise On this setting



Step 7open testmail.php and pass the message you have in MailController 

in mail.blade.php file like below example.



namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels; 
class TestMail extends Mailable
    use Queueable, SerializesModels;
    public $msg;
     * Create a new message instance.
     * @return void
    public function __construct($msg)
        $this->msg = $msg;
     * Build the message.
     * @return $this
    public function build()
        return $this->subject('Test Mail From Teknowize')->view('Email/mail');


Step 8- Run php artisan serve



Result -