how-to-send-email-in-laravel-with-mailtrap

How to send email in laravel 7 with Mailtrap

Hello World, Welcome to projectsplaza.com. Today I am going to show you how to send email in laravel with Mailtrap. This is a very easy and simple tutorial. In this tutorial, I will send a simple email from my controller function. I have divided this tutorial into the following parts.

  • Setup Mailtrap account
  • Connect Mailtrap with laravel
  • Email configuration in laravel
  • Send email from the controller

I have assumed that you have basic knowledge of laravel.


SetUp Mailtrap account

  • Create an account at Mailtrap website https://mailtrap.io/.
  • Get the credentials from your demo inbox.

Connect Mailtrap with laravel

  • Laravel give us provision to setup smtp in .env. Get the credentials from mailtrap account and setup in .env file.

Email configuration in laravel


  • Run the following command to create Mailable class.
  • php artisan make: mail SendNotification
  • Open the above file app/Mai/SendNotifaction.php
  • In the build method, we will add our mail view which should exist in views folder.

Send email from controller

  • Add the following two classes in your controller before start
  • use Illuminate\Support\Facades\Mail;
  • use App\Mail\SendNotification;
  • In Controller method, Add the following code to send mail
  • Mail::to(‘reciever_email’)->send(new VendorNotification());
  • Open the routes/web.php and add the following code in it.
  • Route::get(‘/send-email’,’HomeController@send_email’);
  • Open Browser and hit the URL with /send-email
  • Now check Mailtrap inbox, you will receive a HTML email

I hope this tutorial helps you. Please add your feedback in the comment section. Thank you 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *