laravel markdown email render hrml in inbox
Asked Answered
T

4

5

Recently I upgrade Laravel to 6.13.0. Before the upgrade, my markdown email template was good in design. After upgrade, I am trying to send Laravel Mail in markdown format. But when I test it with MailDev it is rendering HTML format.

My email template looks like.

@component('mail::message')
   @component('mail::panel')
      <div class="row">
        <div class="col-6 bg-gray">
            <span>Time</span>
        </div>
        <div class="col-6 bg-gray">
            <span class="badge">{{ date('jS F g:ia', strtotime($signal->signal_time)) }}</span>
        </div>
    </div>
   @endcomponent
@endcomponent

then its look like this in MailDev..

enter image description here

What can I do now?

Tuyere answered 29/1, 2020 at 9:1 Comment(0)
T
11

I get the solution for this issue. recently Laravel has moved CommonMark as their markdown template. it doesn't convert space. what's why my email template is shown as HTML markup. Now, what has to do to fix it.

I removed all space from my email template files like this.

@component('mail::message')
@component('mail::panel')
<div class="row">
<div class="col-6 bg-gray">
<span>Time</span>
</div>
<div class="col-6 bg-gray">
<span class="badge">{{ date('jS F g:ia', strtotime($signal->signal_time)) }}</span>
</div>
</div>
 @endcomponent
@endcomponent

and that fixed my issue. I think someone gets help from this answer.

Tuyere answered 3/2, 2020 at 6:20 Comment(0)
B
4

Markdown considers indented stuff to be code blocks. So, we just have to de-indent everything.

Example:

@component('mail::message')
<h3>Hi {{ $name }}</h3>
<h2>You are invited to join as a member. Here is your login credentials:</h2>
<br>
<table>
    <tr>
        <td>Email</td>
        <td>{{ $email }}</td>
    </tr>
    <tr>
        <td>Password</td>
        <td>{{ $password }}</td>
    </tr>
</table>
@component('mail::button', ['url' => $url])
    <span>Login Here</span>
@endcomponent

<h4>Thanks,</h4>

@endcomponent
Blowtube answered 26/12, 2021 at 10:39 Comment(0)
C
0

I got the same issue and in my case, i have fixed it with writing all stuff with a @ in one line, so as an example:

File: resources/views/vendor/notifications/email.blade.php

Before (not working, showing linkduration in mail):

@lang('mail.welcome.linkduration', 
  ['linkduration' => $linkduration]
)

After (working)

@lang('mail.welcome.linkduration', ['linkduration' => $linkduration])

I hope, this will help

Conducive answered 29/1, 2020 at 9:25 Comment(0)
G
0

The default panel component strips HTML.

If you want to override the default mail:: component namespace you have to publish the vendor files.

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

Then if you look in resources/views/vendor/mail/markdown/ you will see the comonents which you can edit.

panel.blade.php is just {{ $slot }}, change to {!! $slot !!} to allow unfiltered html.

Also, as a side note, if you are using Markdown, you probably don't want to be using complicated bootstrap & HTML directly anyway.

Read more here: https://laravel.com/docs/6.x/mail#customizing-the-components

Glaswegian answered 29/1, 2020 at 11:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.