Adding a Text View for Markdown Emails in Laravel

skeemer • July 5, 2025

laravel

The problem with Laravel's Markdown notification emails

Laravel has an easy way to use Markdown for email notifications. It even includes themes to handle both HTML and plain text. What's missing is a way to define a separate view to use for the plain text content; you are stuck with a single view. This doesn't look great...

My solution

I extended the MailChannel so that you can create markdown and text views. It does not require updating all of your current views.

1. Extend MailChannel

Create /app/Notifications/Channels/BetterMarkdownMailChannel.php

<?php

namespace App\Notifications\Channels;

use Illuminate\Notifications\Channels\MailChannel;
use Illuminate\Support\Str;

class BetterMarkdownMailChannel extends MailChannel
{
    protected function buildMarkdownText($message)
    {
        // If the view file is named "markdown", check for "text" and use that instead.
        if (
            str_ends_with($message->markdown, '.markdown') &&
            view()->exists($view = Str::replaceMatches('/(\.markdown)$/', '.text', $message->markdown))
        ) {
            return fn ($data) => $this->markdownRenderer($message)->renderText(
                $view, array_merge($data, $message->data()),
            );
        } 

       return parent::buildMarkdownText($message);
    }
}

Bind it in your AppServiceProvider

public function register(): void
{
    // ...
    $this->app->bind(
        \Illuminate\Notifications\Channels\MailChannel::class,
        \App\Notifications\Channels\BetterMarkdownMailChannel::class,
    );
    // ...
}

2. Rename your view

It doesn't matter where you place these, the main thing is to move it from .../view-name.blade.php to .../view-name/markdown.blade.php.

Original path: resources/views/mail/example.blade.php
New path: resources/views/mail/example/markdown.blade.php

And update your notification to the new view path.

Original view: mail.example
New view: mail.example.markdown

3. Create the text view

Copy your markdown.blade.php to text.blade.php and modify it to what you want.

4. Commit

That's all there is to it. This is a non-breaking change, so you don't have to worry about changing every mail view.