Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

djay's avatar
Level 2

Mail Markdown

Hi, Everyone

I am facing some problem in customizing the default Laravel notification mail. By default the title and subject of the message gets repeated, I just want to remove the duplication so that the message part starts immediately

Please see the image link below for clarification https://ibb.co/8BzB5VZ

I can't figure out where to configure

I have already done this-

php artisan vendor:publish --tag=laravel-mail

Please can anyone point me in the right direction

Thanks

0 likes
8 replies
manelgavalda's avatar

Quoting from the docs https://laravel.com/docs/5.7/mail#customizing-the-components:

  • This command will publish the Markdown mail components to the resources/views/vendor/mail directory. The mail directory will contain a html and a markdown directory, each containing their respective representations of every available component. The components in the html directory are used to generate the HTML version of your email, and their counterparts in the markdown directory are used to generate the plain-text version. You are free to customize these components however you like.

You just need to edit the published files in resources/views/vendor/mail directory, and remove the parts you don't need. If you go to resources/views/vendor/mail/html I think you want to edit the message.blade.php file and remove the header section:

    {{-- Header --}}
    @slot('header')
        @component('mail::header', ['url' => config('app.url')])
            {{ config('app.name') }}
        @endcomponent
    @endslot
djay's avatar
Level 2

Hi @globals

Thanks for your reply

{{-- Header --}}
    @slot('header')
        @component('mail::header', ['url' => config('app.url')])
            {{ config('app.name') }}
        @endcomponent
    @endslot

Commenting out above header part will not get the message send

Have you seen this image - https://ibb.co/8BzB5VZ

the duplication of title and subject of message

Thanks

djay's avatar
Level 2

Hi @globals

Notification code:

 public function toMail($notifiable)
    {
        $sub = $this->request['subject'];
        $msg = $this->request['message'];
        $url = $this->request['url'];

        return (new MailMessage)
            ->subject($sub)
            ->markdown('mail.message', ['sub'=>$sub, 'msg'=>$msg, 'url' => $url]);
    }

and mail.message view

@component('mail::message')
# {{$sub}}

{{$msg}}

@component('mail::button', ['url' => $url])
Just Unite
@endcomponent

Thanks,<br>
{{ config('app.name') }}
@endcomponent


Thanks for your reply

Sinnbeck's avatar

In your mail.message you have it defined? Remove # {{$sub}} and you should be fine

djay's avatar
Level 2

@resin

No, it will remove the subject altogether

All I just want to do is remove the repetition of "title and subject of the message" when the mail is unread as shown in this image link:

https://ibb.co/8BzB5VZ

Anyhow thanks for your reply

Sinnbeck's avatar

So you want the subject to both be the subject and be inside the mail body? If not then all you need is this. No need to pass the $sub to markdown()

->subject($sub)

I believe that what you are seeing is just googles default preview. They will always render the title, and then x number of characters from the email body. My best bet to avoid this is to override the text version of the mail with a version without $sub, and hope that gmail will use this in their preview.

djay's avatar
Level 2

Ok, Thanks @resin

I think that somewhere - the title and subject of any mail sent is included again just before the actual body of the message starts that why Gmail is including it - otherwise the markdown template is rendering very properly as required

You are absolutely right Gmail will always render the title and then x number of characters and it should be but in default Laravel markdown if the subject is present it is repeated again - not in the message but in unread messages list of Gmail

Please or to participate in this conversation.