How to Send Mail using Sendgrid in Laravel?

https://www.itsolutionstuff.com/post/how-to-send-mail-using-sendgrid-in-laravel-5example.html

How to Send Mail using Sendgrid in Laravel?

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

.env

MAIL_DRIVER=smtpMAIL_HOST=smtp.sendgrid.netMAIL_PORT=587MAIL_USERNAME=sendgridusernameMAIL_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

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

 Hi, sendgrid testing.

Last updated