How to Send Email in Laravel 8 with Markdown Template Example

In this tutorial you will learn about the How to Send Email in Laravel 8 with Markdown Template Example and its application with practical example.

In this tutorial we will learn how to send email in laravel 8 using mailable and mailtrap. We will use Laravel 8 builtin mailable markdown class to send emails. In order to send email using mailtrap we will implement laravel 8 builtin mailable markdown class. In this post I’ll show you how to integrate mailtrap to send email in laravel 8 application.

Laravel 8 provides builtin mailable markdown class to send emails. In Laravel 8 you can use mailtrap, smtp, Mailgun, Postmark, Amazon SES, and sendmail for sending emails. You are required to configure driver details on the .env file.

How to Send Email in Laravel 8 with Markdown Template Example

In this step by step tutorial you will understand how to send emails in Laravel 8 with the help of Mailtrap. We will explain to you how to use Laravel 8 builtin mailable markdown class to send emails using Mailtrap.

  1. Create Laravel Application
  2. Setting Up Mail Configuration
  3. Define Markdown with Mailable Class
  4. Create & Configure Controller
  5. Prepare Route
  6. Evoke Mail View
  7. Start Application

Create Laravel Application

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Setting Up Mail Configuration

In this step we will be setting smtp detail for mail configuration in Laravel, We will be using following Gmail SMTP details such as username, password inside the .envfile.

If we are sending email from localhost using Gmail SMTP, then it requires you to turn on the “Allow less secure apps” on?. Go to the link provided:

Now, You need to turn on the option “Allow less secure apps”

Define Markdown with Mailable Class

The mailable class in Laravel used for sending emails. Now, lets create a new laravel mailable class using following artisan command:

Once the above command executed, it will create a new laravel mailable class SendDemoMail.php in app/Mail/ directory. Open the SendDemoMail.php file and put the following code in it.

Create & Configure Controller

Now, we will create a controller that will handle the logic to send email. Let’s create ContactController Controller using following command:

Once the above command executed, it will create a controller file ContactController .php in app/Http/Controllers/ directory. Open the ContactController .php file and put the following code in it.

Controllers/ContactController .php

Create Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Create Email Template

In this step, we will create view/blade file to setup email template. Open resources/views/Email/sendDemoMail.blade.php file, put the following code.

resources/views/Email/sendDemoMail.blade.php

Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

In this tutorial we have learn about the How to Send Email in Laravel 8 with Markdown Template Example and its application with practical example. I hope you will like this tutorial.