Markdown Emails Made Simple: Laravel 7 Walkthrough


 How to send Markdown Mail to single and multiple emails in Laravel

Send Markdown Mail in Laravel 7

Laravel provides you different way to send Mail , in this article we learn how to send mail using markdown mails . We will use mailtrap for sending mail in this article . Let's see how to use markdown mail in Laravel .

Table of Content :

  • Setup Mail Configuration
  • Setup your Route
  • Generate Markdown Mail
  • Call your Mail from controller

Step 1  - Setup Mail Configuration :

The very first step is to set up our mail configuration , first setup your mail configuration on your .env file as per your mail credentials as i am using mailtrap for sending emails , Here is how you can setup your mail configurations shown below .

Send Markdown Mail in Laravel 7

.env :


Step 2 - Setup Routes :

Now set up your routes as per your requirement .


Step 3 - Generate Markdown Mail :

Use the following command to create your markdown mail .

php artisan make:mail WelcomeMail --markdown=Email.welcomeMail

It will create WelcomeMail.php file inside your app/Mail directory and another file named welcomeMail.blade.php inside app/resources/views/Email directory .

Step 4 - Calling Mail from Controller :

Now simply call the Mail from your controller function as shown below .

For sending mail to single Mail user .

 public function sendMarkdownMail()
        $email = ''; 

        $data['name'] = 'your name';
        $data['subject'] = 'Signup Mail';
        $data['from'] = '';

        Mail::to($email)->send(new WelcomeMail($data));


For sending mail to multiple Mail users .

public function sendMarkdownMail()
        $emails = ['','','']; 

        $data['name'] = 'your name';
        $data['subject'] = 'Signup Mail';
        $data['from'] = '';

        Mail::to($emails)->send(new WelcomeMail($data));


Note :

Do not forget to use Mail class and the mail file you are calling in the controller .

use Mail;
use App\Mail\WelcomeMail;

WelcomeMail.php :


namespace App\Mail;

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

class WelcomeMail extends Mailable
    use Queueable, SerializesModels;
    protected $data;
     * Create a new message instance.
     * @return void
    public function __construct($data)
        $this->data = $data;

     * Build the message.
     * @return $this
    public function build()
        return $this->markdown('Email.welcomeMail')->from($this->data['from'])->subject($this->data['subject']);

welcomeMail.blade.php :

# Thank you for Registering

Thank you for reading this article and for being a part of our family

@component('mail::button', ['url' => ''])
Demo Button

{{ config('') }}

That's it , now just simple hit your route and check your Mail , you would have got the mail . This article is only giving you the basics of using Laravel Markdown Mail . You can visit Laravel's official site to make more customize your Email .

Output :

Send Markdown Mail in Laravel 7

Post a Comment

Post a Comment (0)