How to Send Mail using Sendgrid in Laravel?

How to Send Mail using Sendgrid in Laravel?

In this post we will give you information about How to Send Mail using Sendgrid in Laravel?. Hear we will give you detail about How to Send Mail using Sendgrid in Laravel?And how to use it also give you demo for it if it is necessary.

Sendgrid is very popular API to send email from our laravel application. It is very fast to send mail and also you can track sended mail. Tracking email is very important feature of Sendgrid api and you can also see how much user open your mail, click on your mail too. In this post i would like to show you how to setting of Sendgrid in our laravel 5 application. In this example you can learn to send simple mail using Sendgrid site. If you are use Sendgrid for sending email then you can save loading time and you can get mail fast.

First we will add configration on mail. i added my gmail account configration. so first open .env file and bellow code:

.env

MAIL_DRIVER=smtp

MAIL_HOST=smtp.sendgrid.net

MAIL_PORT=587

MAIL_USERNAME=sendgridusername

MAIL_PASSWORD=sendgridpassword

Ok, now we need to add secret and domain of sendgrid api configration. So first create new account in sendgrid.com if you don’t have before. After registeration active your sendgrid account and set username and password

Now we are ready to send mail for test so first create test route for email sending.

app/Http/routes.php

Route::get('mail', 'HomeController@mail');

Ok, now add mail function in HomeController.php file so add this way :

app/Http/Controllers/HomeController.php

public function mail()

{

$user = User::find(1)->toArray();

Mail::send('emails.mailEvent', $user, function($message) use ($user) {

$message->to($user->email);

$message->subject('Sendgrid Testing');

});

dd('Mail Send Successfully');

}

At last create email template file for send mail so let’s create mailEvent.blade.php file in emials folder.

resources/views/emails/mailEvent.blade.php

Also see:How to send mail using mailable in laravel 5.3?

Hi, sendgrid testing.

Hope this code and post will helped you for implement How to Send Mail using Sendgrid in Laravel?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

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

3  +  3  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US