How To Send Email In Laravel 8 With Mailable And Mailtrap Example



Sumit Suryavanshi


Laravel send email with mailable and mailtrap example. In this tutorial i will show you how to send mail in laravel with the mailable class. And also you will learn how to create mailable notification class in the laravel web applications

Laravel 8 Send Email/Mail With Mailable

  • Setup SMTP Credentials in .env
  • Make Mailable Class
  • Create Controller with Method
  • Create Route & Blade View
  • Email Send and Test

Setup SMTP Credentials in .env

This is the first step, go to .env file and set SMTP details in .env file.

You could do like:

MAIL_USERNAME=Add your user name here
MAIL_PASSWORD=Add your password here

The above email SMTP details are default and necessary. You can also set the following things:


The above are used by Laravel web applications when you will send emails/mails to users. The from email address and name part of the email that is displayed to users.

Make Mailable Class

You can use the php artisan make:mail command to create a new mailable class in your laravel web application.

You could do like:

php artisan make:mail MailNotification

After that go to app/Mail and update the following code into your MailNotification class:

namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class MailNotification 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('');
        //here is your blade view name

Create Controller with Method

This is the second step. in this step, we will create a controller for sending emails/mails.

Just open your command prompt (CMD) and go to your project root directory. Then type the below command for creating a new controller.

php artisan make:controller MailController

After that, You need to create one method in your controller. So go to the => app/Http/Controllers/MailController.php And update the below given code into your controller:

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Redirect,Response,DB,Config;
use Mail;

class MailController extends Controller
    public function sendEmail()
        $data['title'] = "This is first mail from";
        $data['name']= '';

        Mail::to($user)->send(new MailNotify($data));
        if (Mail::failures()) {
           return response()->Fail('Sorry! Please try again latter');
           return response()->success('Great! Successfully send in your mail');

Create Route & Blade View

Next step, here you need to create one route and one blade view file.

So go to routes/web.php and update the following route in your file:

use App\Http\Controllers\MailController;

Route::get('lara-email-send', [MailController::class, 'sendEmail']);

After that, go to your resources/views/ and create a new blade view file name email.blade.php and update the below code into your file:

<!DOCTYPE html>
 <title>Laravel Send Email Example</title>

 <h1>This is first mail using laravel mailable class </h1>
 <p>Thank you, {{ $name }}</p>


Email Send And Test

Hit the following URL in your browser and test:


If you are not run PHP artisan server command, direct go to your browser and type the URL