Laravel 8 Send Email Example

In this example we will show laravel 8 send email example. we explain step by step laravel 8 how to send email.

This post you learn example of send email in laravel 8 smtp. laravel 8 provide mail class to send email.  we will learn send email in laravel 8.

In this example we will discuss full example of send email in laravel 8. laravel 8 provide Mail facade for mail send that have many method for send email. in this example i explain how to send emails from gmail account example.

Step 1: .env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=mygoogle@gmail.com
MAIL_PASSWORD=rrnnucvnqlbsl
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=mygoogle@gmail.com
MAIL_FROM_NAME="${APP_NAME}"

Step 2:Create Route

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\SendMailController;


Route::get('/send-mail', [SendMailController::class, 'index'])->name('send.mail.index');

Step 3: Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;
use Mail;

class SendMailController extends Controller
{
    public function index()
    {
    	$user = User::find(1)->toArray();
    	
    	Mail::send('mail', $user, function($message) use ($user) {
            $message->to($user['email']);
            $message->subject('Welcome Mail');
    	});

    	dd('Mail Send Successfully');
    }
}

Step 4: Cretae View

In this step we will create email template file for send mail. so let’s create mail.blade.php file in emials folder.

Read also : Razorpay Payment Gateway Integration in Laravel

Hi {{ $name }}, How are you ?.

After complete all steps you run the following command:

php artisan serve

Now you can open the followinf URL on your browser:

http://localhost:8000/send-mail

I hope you understand of laravel 8 send email example and it can help you…