Laravel 10 Send Mail using Markdown Template

Websolutionstuff | Dec-04-2023 | Categories : Laravel PHP

Hey everyone! Ever wondered how to make your Laravel emails look sleek and professional? In this guide, I'll walk you through the simple steps of sending emails using Markdown templates in Laravel 10. Let's make your email communication stand out!

In this post, we will explore how to send Markdown mail in Laravel 10. The article presents a straightforward example of sending markdown-formatted emails in Laravel 10, demonstrating the process of sending emails using mailables.

Laravel 10's Markdown feature comes with built-in, predefined mail templates and components for crafting stylish emails, including tables, links, buttons, and embedded images. Upgrade your email communication with the versatility of Laravel 10 Markdown.

So, let's see sending markdown emails in Laravel 8, Laravel 9, and Laravel 10.

Step 1: Install Laravel 10

If you haven't already, start by creating a new Laravel project using Composer:

composer create-project laravel/laravel your-project-name
cd your-project-name


Step 2: Add Mail Configuration

Configure mail configuration in the .env file.

[email protected]
[email protected]


Step 3: Generate the Mailable Class with Markdown

 Run the following Artisan command to generate a new Mailable class. This class will use Markdown for email formatting:

php artisan make:mail TestMail --markdown=emails.testMail

After running the command, navigate to the app/Mail directory in your Laravel project. You will find a new file named TestMail.php. Open this file to customize your Mailable class.


namespace App\Mail;

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

class TestMail extends Mailable
    use Queueable, SerializesModels;
    public $details;

    public function __construct($details)
        $this->details = $details;

     * Get the message envelope.
    public function envelope(): Envelope
        return new Envelope(
            subject: 'This E-mail from Websolutionstuff',
     * Get the message content definition.
    public function content(): Content
        return new Content(
            markdown: 'emails.testMail',
     * Get the attachments for the message.
     * @return array

    public function attachments(): array
        return [];



Step 4: Create TestMailController

Execute the following command to generate a new controller:

php artisan make:controller TestMailController



namespace App\Http\Controllers;

use App\Mail\TestMail;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;

class TestMailController extends Controller
    public function sendMail()
        $details = [
            'title' => 'This E-Mail from Websolutionstuff',
            'url' => ''

        // Customize the logic for sending the email
        $recipient = '[email protected]';

        // Send the email using the Mailable class
        Mail::to($recipient)->send(new TestMail($details));

        return "Test email sent to $recipient";


Step 5: Define a Route

Open the routes/web.php file and define a route that maps to the sendMail method in your controller.

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\TestMailController;
| Web Routes
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
Route::get('send-mail', [TestMailController::class, 'sendMail']);


Step 6: Design the Markdown Template

The Markdown template associated with this Mailable class is located at resources/views/emails/testMail.blade.php. Open this file to design your email using Markdown syntax.

    # Hello! {{ $details['title'] }}

    This is a test email with Markdown.

    @component('mail::button', ['url' => $details['url']])
    Visit Our Website

    {{ config('') }}


Step 7: Run the Laravel Server

Run the following command to start the Laravel development server

php artisan serve



And there you have it! Sending beautifully crafted emails using Markdown templates in Laravel 10 has never been easier. Elevate your email communication with styled and professional-looking messages, enhancing the overall user experience.

Happy coding!


You might also like:

Recommended Post
Featured Post
Laravel 9 whereNull / whereNotNull Query Example
Laravel 9 whereNull / whereNot...

In this article, we will see the laravel 9 whereNull / whereNotNull query example. In laravel 9 additional where clauses...

Read More


Localization - Laravel Localization Example
Localization - Laravel Localiz...

In this article, we will see localization - laravel localization example. Laravel's localization features provide a...

Read More


How To Create Custom Helper Function In Laravel 10
How To Create Custom Helper Fu...

In this article, we'll explore how to create a custom helper function in Laravel 10. This custom helper function can...

Read More


Laravel 9 whereBetween Query Example
Laravel 9 whereBetween Query E...

In this article, we will see laravel 9 whereBetween query example. The whereBetween() method is used to check value...

Read More