Laravel 9 Send Mail using Sendgrid Tutorial

May 11, 2022 . Admin

Hi Guys,

In this tutorial, I will learn you how to send mail using sendgrid in laravel can easy and simply send mail via sendgrid in laravel 9.

Sendgrid is a very popular API to send email from our laravel application. It is very fast to send mail and also you can track sent mail. Tracking email is a very important feature of Sendgrid api and you can also see how many users open your mail, and click on your mail too.

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

Step 1: Download Laravel

Let us begin the tutorial by installing a new laravel application. if you have already created the project, then skip the following step.

composer create-project laravel/laravel example-app
Step 2: .env file

Check your .env file and configure these variables:

Step 3: Create Mail

Next you need to create a Mailable class, Laravel's CLI tool called Artisan makes that a simple feat. Open CLI, go to the project directory and type:

php artisan make:mail sendGrid --markdown=emails.sendGrid

This command will create a new file under app/Mail/SendGrid.php and it should look something like this:


namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class SendGrid extends Mailable
    use Queueable, SerializesModels;

    public $input;
     * Create a new message instance.
     * @return void
    public function __construct($input)
        $this->input = $input;

     * Build the message.
     * @return $this
    public function build()
        return $this->markdown('emails.sendGrid')
                        'message' => $this->input['message'],
                    ->from('', 'Vector Global')
Step 4: Create Route

Here, we need to add a simple route for postcontroller. so open your "routes/web.php" file and add the following route.


use App\Http\Controllers\PostController;

| Web Routes
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!

Route::get('mail/send-grid', [PostController::class, 'sendMail']);
Step 5: Create Controller

In this step, now we should create new controller as PostController. So run bellow command and create new controller.

php artisan make:controller PostController

So, let's copy bellow code and put on PostController.php file.


namespace App\Http\Controllers;

use Illuminate\Routing\Controller;
use Illuminate\Http\Request;
use Validator;
use App\Mail\SendGrid;

class PostController extends Controller
     * Write code on Method
     * @return response()
    public function sendMail(Requset $request)
        $input = ['message' => 'This is a test!'];

        Mail::to('')->send(new SendGrid($input));
Step 6: Create Blade Files

In last step. In this step, we have to create just a blade file. so we need to create only one blade file as a sendGrid.blade.php file.

# Introduction

{{ $message }}

@component('mail::button', ['url' => ''])
Button Text

{{ config('') }} @endcomponent
Run Laravel App:

All steps have been done, now you have to type the given command and hit enter to run the laravel app:

php artisan serve

Now, you have to open web browser, type the given URL and view the app output:


It will help you...

#Laravel 9