Laravel 5.4^ - 如何自定义通知电子邮件布局?

标签 laravel laravel-5 laravel-5.4

我正在尝试自定义通过电子邮件发送通知时使用的 HTML 电子邮件布局。

我已经发布了邮件和通知 View 。
php artisan vendor:publish --tag=laravel-mailphp 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 获取我的通知以发送电子邮件?

enter image description here

以下是我的/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

这就是我得到的:

enter image description here

关于Laravel 5.4^ - 如何自定义通知电子邮件布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42724118/

相关文章:

laravel - 如何通过公共(public) URL 从存储中获取文件?

php - laravel 5.4.12注册成功后如何自动登录?

mysql - 正确的 Laravel Join with Date 修复

laravel - 即使查询返回结果,Twitter-typeahead 也不会显示任何结果

php - 如何在 View 中访问 Laravel 类?

php - Laravel 表单验证独特,使用 2 个字段

laravel - 如何同时运行多个Laravel项目?

php - ReflectionException 类 UserController 不存在 Laravel5.4

php - 如果 id 相同,Laravel 验证唯一性

php - 想要获得两个值之间的差异