Laravel 9 Send Email Tutorial Example




Laravel 9 Send Email Tutorial Example

Hi all,

In this example, you will learn the laravel 9 send email tutorial example. if you want to see an example of sending an email in laravel 9 SMTP then you are in the right place. we will help you to give the example of laravel 9 send mail example. This tutorial will give you a simple example of laravel 9 sends mail example. Follow the below tutorial step of step-by-step send mail laravel 9 using SMTP.

In this tutorial, we will discuss how to configure our Laravel 9 applications to send emails using your Gmail account as a Gmail SMTP server with the default Laravel SMTP configurations.

To send emails in Laravel 9, the framework provides several advanced features to work with. It has different packages available in the market that makes the integration of emailing functionality effortless.

Step 1: Download Laravel

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

composer create-project laravel/laravel example-app

Step 2: Make Configuration

In the first step, you have to add send mail configuration with mail driver, mail host, mail port, mail username, mail password so laravel 9 will use those sender configurations for sending the email. So you can simply add as like following.







Step 3: Add Mail Class

In this step, we will create a mail class DemoMail for email sending. Here we will write code for which view will call and object of user. So let's run bellow the command.

php artisan make:mail SendMail

now, let's update code on SendMail.php file as bellow:



namespace App\Mail;

use Illuminate\Bus\Queueable;

use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Mail\Mailable;

use Illuminate\Queue\SerializesModels;

class SendMail extends Mailable


use Queueable, SerializesModels;

public $mailData;


* Create a new message instance.


* @return void


public function __construct($mailData)


$this->mailData = $mailData;



* Build the message.


* @return $this


public function build()


return $this->subject('Mail from')




Step 4: Add Controller

In this step, we will create SendMailController with index() method where we write code for sending mail to given email address. so first let's create controller by following command and update code on it.

php artisan make:controller SendMailController

Now, update the code on the SendMailController file.



namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Mail;

use App\Mail\SendMail;

class SendMailController extends Controller



* Write code on Method


* @return response()


public function index()


$mailData = [

'title' => 'Send mail from',

'body' => 'This is for testing email using smtp.'


Mail::to('')->send(new SendMail($mailData));

dd("Email is sent successfully.");



Step 5: Add Routes

In this step, we need to create routes for a list of sending emails. so open your "routes/web.php" file and add the following route.



use Illuminate\Support\Facades\Route;

use App\Http\Controllers\SendMailController;



| 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', [SendMailController::class, 'index']);

Step 6: Add Blade View

In this step, we will create a blade view file and write the email that we want to send. now we just write some dummy text. create bellow files on the "emails" folder.


<!DOCTYPE html>






<h1>{{ $mailData['title'] }}</h1>

<p>{{ $mailData['body'] }}</p>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod

tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,

quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo

consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse

cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non

proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

<p>Thank you</p>



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:



I hope it can help you...

#Laravel 9