Laravel通过电子邮件发送原始HTML



我正在尝试发送电子邮件,不幸的是,电子邮件html标签NOT没有被解析,用户将html标签视为文本,我已经上网12个小时了,但问题仍然存在

降价模板(notification.email.blade.php(

@component('mail::message')
{{-- Greeting --}}
@if (! empty($greeting))
# {{ $greeting }}
@else
@if ($level === 'error')
#@lang('اوه اوه!')
@else
#@lang('سلام!')
@endif
@endif
{{-- Intro Lines --}}
@foreach ($introLines as $line)
{{ $line }}
@endforeach
{{-- Action Button --}}
@isset($actionText)
<?php
switch ($level) {
case 'success':
case 'error':
$color = $level;
break;
default:
$color = 'primary';
}
?>
@component('mail::button', ['url' => $actionUrl, 'color' => $color])
{{ $actionText }}
@endcomponent
@endisset
{{-- Outro Lines --}}
@foreach ($outroLines as $line)
{{ $line }}
@endforeach
{{-- Salutation --}}
@if (! empty($salutation))
{{ $salutation }}
@else
#@lang('با احترام'),{{ config('app.name') }}
@endif
{{-- Subcopy --}}
@isset($actionText)
@component('mail::subcopy')
@lang("اگر مشکلی در کلیک کردن بر روی ":actionText" دارید, لینک زیر را کپی n".'و داخل مرورگر گذاشته: [:actionURL](:actionURL)',['actionText' => $actionText,'actionURL' => $actionUrl,])
@endcomponent
@endisset
@endcomponent

vendor/mail/html/messageblade.php

@component('mail::layout')
{{-- Header --}}
@slot('header')
@component('mail::header', ['url' => config('app.url')])
{{ config('app.name') }}
@endcomponent
@endslot
{{-- Body --}}
{{ $slot }}
{{-- Subcopy --}}
@isset($subcopy)
@slot('subcopy')
@component('mail::subcopy')
{{ $subcopy }}
@endcomponent
@endslot
@endisset
{{-- Footer --}}
@slot('footer')
@component('mail::footer')
© {!! date('Y') !!} @lang('تمامی حقوق برای') {!! config('app.name') !!}  @lang('محفوظ می باشد')
@endcomponent
@endslot
@endcomponent

vendor/mail/html/layoutblade.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<style>
@media only screen and (max-width: 600px) {
.inner-body {
width: 100% !important;
}
.footer {
width: 100% !important;
}
}
@media only screen and (max-width: 500px) {
.button {
width: 100% !important;
}
}
</style>
<table class="wrapper" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td align="center">
<table class="content" width="100%" cellpadding="0" cellspacing="0">
{{ $header ?? '' }}
<!-- Email Body -->
<tr>
<td class="body" width="100%" cellpadding="0" cellspacing="0">
<table class="inner-body" align="center" width="570" cellpadding="0" cellspacing="0">
<!-- Body content -->
<tr>
<td class="content-cell">
{{ IlluminateMailMarkdown::parse($slot) }}
{{ $subcopy ?? '' }}
</td>
</tr>
</table>
</td>
</tr>
{{ $footer ?? '' }}
</table>
</td>
</tr>
</table>
</body>
</html>

电子邮件代码

return (new MailMessage)
->greeting('Hello!')
->line('One of your invoices has been paid!')
->action('View Invoice', '#')
->line('Thank you for using our application!')->markdown('vendor.notifications.email');
}

部分输出

<tr> <td class="header"> <a href="http://localhost"> Rabter </a> </td> </tr> <tr> <td> <table class="footer" align="center" width="570" cellpadding="0" cellspacing="0"> <tr> <td class="content-cell" align="center"> &lt;p&gt;é 2020 êÃÂçÃÂàíÃÂÃÂàèñçÃÂÃÂíÃÂÃÂø ÃÂàèçôï&lt;/p&gt; </td> </tr> </table> </td> </tr>

我不知道如何修复它,我已经在本地主机和共享主机上进行了测试感谢的帮助

Laravel允许您parse任何类似HTML的满足感,这样标记就会自动从视图中剥离出来。

在您的notification.blade.php中,您可以解析如下所示的所有文本

{!! (new Parsedown)->text('Body of your email or text to be viewed by the mail reader) !!}

你可以关注这个博客来获得更详细的解释https://zubair.dev/blog/how-markdown-emails-work-in-laravel-using-league-commonmark-package

希望这对你有用!!

最新更新