Send Mail Example In Laravel 8

Websolutionstuff | Oct-16-2020 | Categories : Laravel

In this article, we will see send mail in laravel 8. here we will see how to send mail in laravel 8. Email is a very basic and important feature in the web development field and it is necessary for all clients to send and receive information and important data. So, in this tutorial, we will learn information about sending mail in laravel 8.

Laravel and SwiftMailer provide drivers for sending email via SMTP, Mailgun, Postmark, and Amazon SES. Also, you can send mail through local or cloud-based services.

So, let's see how to send mail in laravel 8.

Laravel 8 Mail - Laravel 8 Send Mail Example

Step 1: Setup DatabaseConfiguration

In this step we will set the configuration in the .env file for sending mail, here we are using SMTP and mailtrap.

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your_username
MAIL_PASSWORD=your_password
MAIL_ENCRYPTION=TLS

 

 

Step 2: Create Mail Using Artisan Command

Laravel provides a built-in mail class for sending mail. So, we need to create testmail class for the same,

php artisan make:mail TestMail

 app/Mail/TestMail.php

<?php

namespace App\Mail;

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

class TestMail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('mail.Test_mail');
    }
}

 

Step 3: Create Blade File

Now, we will create a Test_mail.blade.php file.

view/mail/Test_mail.blade.php

Hi <br/>
This is Test Mail From Websolutionstuff. <br />
Thank you !!

 

 

Step 4: Create Send Mail Route

Now, Create a route for testing and send mail in laravel 8.

Route::get('test_mail','App\Http\Controllers\EmailController@testMail');

 

Step 5: Create EmailController

 Now create EmailController and add the below code.

public function testMail()
{
	$mail = '[email protected]';
	Mail::to($mail)->send(new TestMail);

	dd('Mail Send Successfully !!');
}

 

 

Output:

send_mail_in_laravel_8

 


You might also like:

Recommended Post
Featured Post
How to Display Validation Error Message in Laravel Vue JS
How to Display Validation Erro...

Hey folks, are you ready to make your Laravel Vue.js application even more user-friendly by implementing validation erro...

Read More

Mar-08-2024

How To Install phpMyAdmin In Ubuntu
How To Install phpMyAdmin In U...

In this article, we will explore the process of installing phpMyAdmin in Ubuntu. phpMyAdmin is a popular web-based admin...

Read More

Jul-24-2023

Laravel 8 Yajra Datatable Example Tutorial
Laravel 8 Yajra Datatable Exam...

In this article, we will see the laravel 8 yajra datatable example tutorial. Datatable provides users to many...

Read More

Sep-30-2020

How To Validate Password And Confirm Password In React JS
How To Validate Password And C...

In this article, we will see how to validate password and confirm password in react js. Sometimes we need to add th...

Read More

Sep-14-2022