How to send mail using mailable in laravel 5.3?By Hardik Savani | August 31, 2016 | | 35546 Viewer | Category : PHP Laravel
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 = 'email@example.com';
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...
- Bootstrap - Show/Hide(toggle) Password input field using bootstrap-show-password.js Plugin
- How to add custom jquery validation for image file upload in summernote ?
- PHP - Bootstrap autocomplete tokenfield with Ajax Example
- How to check file size when select multiple file validation using Jquery?
- How to check file is exists or not in PHP?
- How to solve - This cache store does not support tagging?
- Laravel 5.3 - whereDate(), whereMonth(), whereDay() and whereYear() examples.
- How to set value as key in PHP array?