Laravel 5.4^ - 如何自定义通知电子邮件布局? [英] Laravel 5.4^ - How to customize notification email layout?

查看:24
本文介绍了Laravel 5.4^ - 如何自定义通知电子邮件布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自定义通过电子邮件发送通知时使用的 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'){{-- 问候--}}@if (!empty($greeting))# {{ $问候}}@别的@if ($level == '错误')#哎呀!@别的# 你好!@万一@万一{{-- 介绍行 --}}@foreach ($introLines 作为 $line){{ $line }}@endforeach{{-- 动作按钮 --}}@if (isset($actionText))<?php开关($级别){案例'成功':$color = '绿色';休息;案例'错误':$color = '红色';休息;默认:$color = '蓝色';}?>@component('mail::button', ['url' => $actionUrl, 'color' => $color]){{ $actionText }}@结束组件@万一{{-- 尾声 --}}@foreach ($outroLines 作为 $line){{ $line }}@endforeach<!-- 敬礼-->@if (!empty($salutation)){{ $salutation }}@别的问候,<br>{{ config('app.name') }}@万一<!-- 子副本-->@if (isset($actionText))@component('mail::subcopy')如果您在点击{{ $actionText }}"按钮时遇到问题,请复制并粘贴以下网址进入您的网络浏览器:[{{ $actionUrl }}]({{ $actionUrl }})@结束组件@万一@结束组件

解决方案

运行此命令

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

<块引用>

laravel 5.7+ 的更新

php artisan vendor:publish

然后你会得到:

 [] 标签:laravel-mail[] 标签:laravel-notifications

然后只需在前面输入该数字即可发布文件进行编辑

<小时>

然后在

/resources/views/vendor/mail/html/

您可以编辑所有组件并自定义您想要的任何内容.例如,我编辑了保留所有权利"这句话.到此文件中该图像底部的保留所有测试":

/resources/views/vendor/mail/html/message.blade.php

这就是我得到的:

I am trying to customize the HTML email layout that is used when sending notifications via email.

I have published both the mail and notification views.

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

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

If I modify the /resources/views/vendor/notifications/email.blade.php file, I can only change the BODY content of the emails that get sent. I am looking to modify the footer, header, and every other part of the email layout as well.

I tried also modifying the views inside /resources/vendor/mail/html/, but whenever the notification gets sent, it is not even using these views and instead uses the default laravel framework ones.

I am aware I can set a view on the MailMessage returned by my Notification class, but I want to keep the standard line(), greeting(), etc. functions.

Does anyone know how I can get my notifications to send email using the views in /resources/vendor/mail/html ?

The following is my /resources/views/vendor/notifications/email.blade.php file, but it does not have anywhere to customize the header/footer/ overall layout.

@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

解决方案

Run this command

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

update for laravel 5.7+

php artisan vendor:publish

and then you will get:

  [<number>] Tag: laravel-mail
  [<number>] Tag: laravel-notifications

and then just type in that number in front to publish the file for editing


and then in

/resources/views/vendor/mail/html/

you can edit all the components and customize anything you want. For example i have edited the sentence "All rights reserved". to "All test reserved" at the bottom of that image inside this file:

/resources/views/vendor/mail/html/message.blade.php

and this is what i got:

这篇关于Laravel 5.4^ - 如何自定义通知电子邮件布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆