我正在尝试自定义通过电子邮件发送通知时使用的 HTML 电子邮件布局。
我已经发布了邮件和通知 View 。php artisan vendor:publish --tag=laravel-mail
php artisan vendor:publish --tag=laravel-notifications
如果我修改 /resources/views/vendor/notifications/email.blade.php
文件,我只能更改发送的电子邮件的正文内容。我希望修改页脚、页眉和电子邮件布局的所有其他部分。
我也尝试修改内部的 View /resources/vendor/mail/html/
,但无论何时发送通知,它甚至不使用这些 View ,而是使用默认的 Laravel 框架 View 。
我知道我可以在 MailMessage
上设置 View 由我的 Notification 类返回,但我想保持标准 line()
, greeting()
等功能。
有谁知道如何使用 /resources/vendor/mail/html
中的 View 获取我的通知以发送电子邮件?
以下是我的/resources/views/vendor/notifications/email.blade.php
文件,但它没有任何地方可以自定义页眉/页脚/整体布局。
@component('mail::message')
{{-- Greeting --}}
@if (! empty($greeting))
# {{ $greeting }}
@else
@if ($level == 'error')
# Whoops!
@else
# Hello!
@endif
@endif
{{-- Intro Lines --}}
@foreach ($introLines as $line)
{{ $line }}
@endforeach
{{-- Action Button --}}
@if (isset($actionText))
<?php
switch ($level) {
case 'success':
$color = 'green';
break;
case 'error':
$color = 'red';
break;
default:
$color = 'blue';
}
?>
@component('mail::button', ['url' => $actionUrl, 'color' => $color])
{{ $actionText }}
@endcomponent
@endif
{{-- Outro Lines --}}
@foreach ($outroLines as $line)
{{ $line }}
@endforeach
<!-- Salutation -->
@if (! empty($salutation))
{{ $salutation }}
@else
Regards,<br>{{ config('app.name') }}
@endif
<!-- Subcopy -->
@if (isset($actionText))
@component('mail::subcopy')
If you’re having trouble clicking the "{{ $actionText }}" button, copy and paste the URL below
into your web browser: [{{ $actionUrl }}]({{ $actionUrl }})
@endcomponent
@endif
@endcomponent
最佳答案
运行这个命令
php artisan vendor:publish --tag=laravel-notifications
php artisan vendor:publish --tag=laravel-mail
update for laravel 5.7+
php artisan vendor:publish
然后你会得到:
[<number>] Tag: laravel-mail
[<number>] Tag: laravel-notifications
然后只需在前面输入该数字即可发布文件进行编辑
然后在
/resources/views/vendor/mail/html/
您可以编辑所有组件并自定义您想要的任何内容。
例如,我编辑了“保留所有权利”这句话。到此文件中该图像底部的“保留所有测试”:
/resources/views/vendor/mail/html/message.blade.php
这就是我得到的:
关于Laravel 5.4^ - 如何自定义通知电子邮件布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42724118/