How to send mail using mailable in laravel 5.3?
Laravel 5.3 released few days ago, that update several part from laravel 5.2, Laravel 5.3 also change mail sending function. Laravel 5.3 introduce mailable class for mail sending like Laravel 5.3 event and mailable class provide several method like view(), from(), text() etc. Mail send example is pretty interesting then laravel other version and also very simple with fully customize.
Today, i am going to tell you how to send simple email with gmail smtp configuration using laravel 5.3 mailable class. It is very simple and best way. you have to just follow few step and you will get simple mail send example in your laravel 5.3 application.
Follow bellow step in your laravel 5.3 project.
Step 1: Mail Configuration
In first step you have to add your gmail smtp configuration like your username, password etc, so open your .env file and add your configration.
If you don't know how to do configuration or found any error about gmail authentication then you can follow this link : How to set gmail configration for mail in Laravel?.
Step 2: Create Mailable Class
Laravel 5.3 introduce new mailable class that way we can use simply like laravel 5.2 event, you can re-use anywhere in your laravel application. So first create Mailable class using artisan command, so fire bellow command:
php artisan make:mail MyTestMail
Ok, Now you can see new file in your app(app/Mail/MyTestMail.php) folder. So, open that file and put bellow code.
class MyTestMail extends Mailable
use Queueable, SerializesModels;
* Create a new message instance.
* @return void
public function __construct()
* Build the message.
* @return $this
public function build()
Step 3: Add Route
In this step, we will add new route for out testing mail so open your web route file and add bellow route.
Step 4: Add Controller Method
Now, we will add myTestMail() in "HomeController" Controller file, in this file we will write code of mail send, so if you haven't created HomeController then create HomeController.php file and put bellow code.
class HomeController extends Controller
* Send My Test Mail Example
* @return void
public function myTestMail()
$myEmail = 'firstname.lastname@example.org';
dd("Mail Send Successfully");
Step 5: Add View File
In last step, we will create email template file, so first create "emails" folder in your resources folder and create myTestMail.blade.php file and put bellow code.
This is My Test Mail.
Ok, now you ready to run our test example, so check it...