Laravel 6 Send Mail using Mailable Class
Teams applying “Laravel 6 Send Mail using Mailable Class” in a production project can use employee self service ess to record implementation, review and debugging time, then compare that effort with tests and shipped functionality instead of treating activity as performance by itself.
Before copying the example into a live application, confirm version-specific behaviour with the official Laravel website and test it against the project’s actual database and runtime.
Hi Dev,
Today, I want to give you example of how to send email using markdown mailable class in laravel 6. It is very easy to send mail with markdown good mail template design in laravel 6.
markdown mailable provide beutiful email layout by defualt in laravel 6. we can use their template design to sending email in laravel 6.
We will give you very simple example of mailable class to send email in laravel 6 application.You have to follow bellow step and you will get simple mail send example in laravel 6.
Step 1: Mail Configuration
In first step you can to add your gmail smtp configuration in .env file.
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=mypassword
MAIL_ENCRYPTION=tls
Step 2: Create Mailable Class
Laravel 6 provide mailable artisan command to create mail file and view file create and you can design custom mail template. so fire bellow command:
php artisan make:mail MyTestMail --markdown=emails.myDemo
Ok, Now you can see new file in your app(app/Mail/MyTestMail.php) folder. So, open that file and put bellow code.
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
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()
{
return $this->markdown('emails.myDemo');
}
}
Step 3: Add Route
In this step you will add bellow route in your route file
routes/web.php
Route::get('my-test-mail','MyTestController@myTestMail');
Step 4: Create Controller File
In this step we will create controller file to use artisan command. so fire bellow command:
php artisan make:controller MyTestController
Step 5: Add Controller Method
Now, we will create controller file and add myTestMail() method in "MyTestController" or put bellow code in MyTestController.
app/Http/Controllers/MyTestController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Mail;
use App\Mail\MyTestMail;
class MyTestController extends Controller
{
public function myTestMail()
{
$myEmail = '[email protected]';
Mail::to($myEmail)->send(new MyTestMail());
dd("Mail Send Successfully");
}
}
It will help you....
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial