【发布时间】:2017-08-01 03:16:50
【问题描述】:
我正在尝试自定义通过电子邮件发送通知时使用的 HTML 电子邮件布局。
我已经发布了邮件和通知视图。
php artisan vendor:publish --tag=laravel-mail
php artisan vendor:publish --tag=laravel-notifications
如果我修改/resources/views/vendor/notifications/email.blade.php 文件,我只能更改所发送电子邮件的正文内容。我希望修改页脚、页眉和电子邮件布局的所有其他部分。
我也尝试修改 /resources/vendor/mail/html/ 中的视图,但是每当发送通知时,它甚至都没有使用这些视图,而是使用默认的 laravel 框架。
我知道我可以对 Notification 类返回的 MailMessage 设置视图,但我想保留标准的 line()、greeting() 等函数。
有谁知道我如何使用/resources/vendor/mail/html 中的视图获取发送电子邮件的通知?
以下是我的/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
【问题讨论】:
-
是的,我想在页眉中添加公司徽标和标语,在页脚中添加一些链接,以及更改 CSS 字体样式
-
是的,这是一个通知。我的通知有一个 toMail 方法可以将通知作为电子邮件
return (new MailMessage)等发送。我正在尝试弄清楚如何自定义new MailMessage的布局 -
我的通知工作正常,我只想让它在通过 toMail 方法发送时使用我自己的电子邮件模板。
-
$user->notify(new TeamInvitation()) -
我的办公网络由于某种原因阻止了该链接。我的通知确实有效,并且我正确收到了包含正确正文的电子邮件。我没有从该文件中删除任何代码。我运行了发布命令,这就是我得到的。
标签: laravel laravel-5 laravel-5.4