Send Mail Example In Laravel 8

WebSolutionStuff | Oct-16-2020 | Categories : Laravel

Hello Guys,

In this post i will give you demo Send Mail Example in Laravel 8.here i will show you how to send mail in laravel 8, email is very basic and most important feature in web development field and it is neccesory for all client to send and receive information and important data.

So, in this tutorial i will give you information about send mail in laravel 8. So, let's start and follow below steps.

 

 

Step 1: Set Configuration

In this step we will set configuration in .env file for sending mail, here we are using smtp mailtrape so set according port also as below.

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 provide built-in mail class for sending mail so, we need to create testmail class for same,

php artisan make:mail TestMail

Now you will found file in this location app/Mail/TestMail.php

copy below code for view.

<?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 Test_mail.blade.php file in this path view/mail/Test_mail.blade.php , we need to add some dummy text for email test purpose.

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

 

Step 4 : Create Route

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

Route::get('test_mail','App\Http\Controllers\[email protected]');

 

Step 5 : Create Controller

 Now create UserController and add below code.

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

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

And finally we will see output like below screen print.

send_mail_in_laravel_8

 

Featured Post




Follow us
facebooklogo github instagram twitter