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.


MAIL_PORT=465  #sender email id
MAIL_PASSWORD=xyz@12                   #sender email password
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 = '';
        $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 -




Comments 0

Leave a comment

Coursera, Codeacademy, Udacity, W3Schools, Udemy, Alison, TheNewBoston, edX, P.S.Codewars,Freecodecamp, Managing technical debt blog, Scrimba, Codepen, Codepen/challenges, The Odin Project, htmlreference.​io, cssreference.​io, Frontend Mentor, Dev Challenges, MDN, Code Mentor, Coding Dojo, CSS Battle, Codier, Ace Frontend, Can I Use, CSS Tricks, 30 Seconds of Code,tutorialspoint, Neumorphism, Shaddows Brumm, Fancy Border Radius, Glow Generator, Clothoid Corners, Glassmorphism, Clipy, CSS Filters, Base64 Image, Quantity Queries, Animations, Cubic-Bezier, Keyframes, Wait Animate, Transition.Style, graphic design, web design, website design, website builder, web developer, web designer, webdesign, ecommerce website, web design company, website creator, website designer, responsive web design, web development company, best website design, web design software, web page design, build a website, web developer salary, design website, web design courses, how to design a website, web design inspiration, website layout, web designer salary, web application development, ecommerce website design, web agency, software development company, web design tutorial, web programming, design company, website design templates, what is web designing, web developer jobs, website developer, web design agency, freelance web developer, web design services, freelance web designer, graphic design websites, web solutions, ecommerce website development, free website design, web development courses, webdev, web developers, web development tools, website design services, developpeur web, web design london, website design ideas, web designing and programming, design a website, web design and development, web dev, web development services, homepage design, best designed websites, cheap website design, learn web design, web design templates, web design tools, web design jobs, website design inspiration, web design india, flash website, website developers, designer websites, website services, website design cost, good website design, site design, simple website design, cool website designs, modern website design, graphic designer websites, webcode, best web design software, website making, free web design software, mobile website design, learn web development, front end web developer, how to become a web developer, web developer portfolio, web development company in india, python web development, web development tutorial, website company, website design and development, web company, webdesigning, professional website design, affordable web design, best web design company, creative web design, top website designs, website design pricing, web developer tools, how to develop a website