我正在try 自定义通过邮箱发送通知时使用的HTML邮箱布局.

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.

我还try 在/resources/vendor/mail/html/中修改视图,但每当发送通知时,它甚至不使用这些视图,而是使用默认的laravel框架视图.

我知道我可以设置通知类返回的MailMessage的视图,但我想保留标准的line()greeting()等函数.

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

enter image description here

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

推荐答案

运行这个命令

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


然后在

/resources/views/vendor/mail/html/

您可以编辑所有组件并自定义任何需要的内容.

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

这就是我得到的:

enter image description here

Laravel相关问答推荐

在没有lang/*.json文件的情况下在Laravel项目中实现多语言支持

如何在 Laravel 中使用多对一变形关系

Laravel init 查询多种用途

FileViewFinder.php 第 137 行中的 Laravel 5 InvalidArgumentException:未找到视图 [.admin]

Laravel belongsToMany 关系在两个表上定义本地键

克隆后设置 Laravel 项目

PHP Laravel:如何设置或获取会话数据?

如何在 laravel 中使用 str_replace

Laravel 从现有模型生成迁移

从 Laravel Cashier 获取下一个账单日期

Homebrew PHP 似乎没有链接

PHP Laravel:如何获取客户端浏览器/设备?

控制器外部的 Laravel 访问请求对象

在Lumen框架中启用会话

命令未定义异常

Laravel 4 简单路由无法使用 mod_rewrite 和 .htaccess

laravel - 无法在控制器构造函数中获取会话

使用 Laravel Mix 合并多个文件

如果在 Laravel 5.1 中找不到路由,则显示 404 页面

如何在 Laravel 5.3 中获取当前的语言环境