Hello Guys,

Today I will give you demo how to send email in laravel, in this post we will show how to send email using SMTP in laravel, email is very basic and most important feature in web development field and it is necessary for all client.

Read Also : How To Integrate Paypal Payment Gateway In Laravel

So, in this tutorial i will give you information about send mail in laravel. So, follow below steps.

Step 1: Set Configuration

First of all we need to set configuration in .env file for sending mail, here we are using smtp mailtrape so set according port also as below.

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=TLS

Step 2 : Create Mail Using Artisan Command

Laravel provide ready mate mail class for sending mail so, we need to create testmail class for same,

php artisan make:mail TestMail

Now you can found file in this location app/Mail/TestMail.php

add below code for view.

<?phpnamespace App\Mail;use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class TestMail 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('mail.Test_mail');
}
}

Step 3 : Create Blade File

Now, I have created Test_mail.blade.php file in this path view/mail/Test_mail.blade.php , we need to add some text dummy text for email test purpose.

Hi <br/>
This is Test Mail From Websolutionstuff. <br />
Thank you !!

Step 4 : Create Route

Now, Create route for testing send mail

Route::get('test_mail','UserController@testMail');

Step 5 : Create Controller

Now create UserController and add below code.

public function testMail()
{
$mail = 'websolutionstuff @gmail.com';
Mail::to($mail)->send(new TestMail);
dd('Mail Send Successfully !!');
}

And after that you get output like below screen print.

Send Email In Laravel
Send Email In Laravel

Read Also : REST API In Laravel

Please Don’t Forgot to Like, Share and Claps.

Thanks For Reading !!

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store