Javatpoint Logo
Javatpoint Logo

Send Email with Laravel 7/6 using Markdown Mailable Class

In this section, we are going to learn about sending emails by using the class of Markdown Mailable. The primary feature of any application is sending mail. For this, we will use Laravel 6 or Laravel 7 app and use the Markdown mailable class to send the mail. In our Laravel 6/7, the markdown email template will be used.

The embed image, tables, buttons, components, email links, etc, are provided by the Laravel Markdown. In the email template, we can use the beautiful layout of Markdown. In the below example, we will use the class of Laravel 6 mailable to send the easy email along with the Gmail SMTP configuration. This way is very simple and best to send the email. In order to send the mail, we have to follow the step by step process, which is described as follows:

Step 1:

In this step, we are going to Set Mail Configuration. In this, we will add our Gmail SMTP configuration such as name, password, etc. For this, we will use our .env file and add our configuration, which is described as follows:

.env:

Step 2:

In this section, we are going to Create Mailable Class with Markdown. A new Mailable class is introduced by the Laravel version 6, which provide us to use laravel event. It also provides the facility to re-use them anywhere in the application. For this, we will first create a class of Mailable, and then we will put the below artisan command like this:

Now we will use our app folder and then see a new file. We will use our below file, and then we will put the below code:

app/Mail/MyDemoMail.phpL:

Step 3:

In this step, we are going to Create Route. We will create this for our testing mail. For this, we will use our web route file, and then we will put the below route:

routes/web.php:

Step 4:

In this step, we are going to Create Controller Method. We will Create HomeController as a new controller. After that, we will create a file named HomeController.php. Now we will use our HomeController file and add myDemoMail() into it. Using this file, we can easily write the mail send code, which is described as follows: 

app/Http/Controllers/HomeController.php:

Step 5:

In this step, we are going to Add View File. We will create a file of the email template. For this, we will use our resource folder and create a folder named as “emails”. After that, we will create a file named “myDemoMail.blade.php”. This file will be useful to write the design code. We will add the below code into that file:

resources/views/emails/myDemoMail.blade.php:

Now our above code is ready to run. In order to run the above code quickly, we will use the following command:

Now we can use our browser to open the below url:

After opening this, we can see the following output:

Send Email with Laravel 7/6 using Markdown Mailable Class





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA