繁体   English   中英

如何在Laravel 5.6中使用和自定义HTML电子邮件(不是markdown)?

[英]How to use and customize an HTML email (not markdown) in Laravel 5.6?

因此,我试图在Laravel 5.6中发送HTML电子邮件,并且遇到了一些有趣的问题。

一方面,自定义HTML内容甚至使用默认HTML布局时,文档都非常糟糕。

https://laravel.com/docs/5.6/mail#writing-mailables

有一个“配置视图”部分,它告诉您只需执行以下操作。

return $this->view('emails.orders.shipped');

酷,我正在这样做。 在我的刀片文件中

Here is a test message.

它发送很好。 但是没有任何意义的是,页面还显示您可以运行以下artisan命令来生成默认电子邮件模板。

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

它说:“邮件目录将包含一个html和markdown目录,每个目录包含每个可用组件的各自表示。html目录中的组件用于生成电子邮件的HTML版本。”

该文档还深入介绍了如何自定义和使用这些降价模板。 您只需要在markdown刀片文件顶部调用@component('mail::message') ...但我不希望markdown 我只想要普通的HTML电子邮件。

@component('mail::message') ->view()仅在使用->markdown()时才使用->view()时不起作用。 我也不能仅执行以下操作。

@extends('vendor.mail.html.layout')
Test message

正如它告诉我的那样,slot是错误日志中的未定义变量。

不知道为什么,/ vendor / mail / html /目录中的layout.blade.php文件包含以下内容...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
    <style>
        @media only screen and (max-width: 600px) {
            .inner-body {
                width: 100% !important;
            }

            .footer {
                width: 100% !important;
            }
        }

        @media only screen and (max-width: 500px) {
            .button {
                width: 100% !important;
            }
        }
    </style>

    <table class="wrapper" width="100%" cellpadding="0" cellspacing="0">
        <tr>
            <td align="center">
                <table class="content" width="100%" cellpadding="0" cellspacing="0">
                    {{ $header ?? '' }}

                    <!-- Email Body -->
                    <tr>
                        <td class="body" width="100%" cellpadding="0" cellspacing="0">
                            <table class="inner-body" align="center" width="570" cellpadding="0" cellspacing="0">
                                <!-- Body content -->
                                <tr>
                                    <td class="content-cell">
                                        {{ Illuminate\Mail\Markdown::parse($slot) }}

                                        {{ $subcopy ?? '' }}
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>

                    {{ $footer ?? '' }}
                </table>
            </td>
        </tr>
    </table>
</body>
</html>

不知道为什么在电子邮件的html版本中调用Markdown::parse($slot)

如何在HTML电子邮件中扩展此视图? 希望至少获得默认的html模板而不必构建自己的HTML模板...

需要HTML时,您正在研究markdown组件。 不要被生成的html目录所迷惑,因为它是降价电子邮件的HTML表示形式。

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

此命令仅用于将标准Markdown组件发布到您的应用程序,因此您可以自定义Mardown电子邮件的呈现方式(以HTML和纯文本格式)。 您只需要HTML电子邮件,而不是markdown,因此运行对您毫无用处。

它在电子邮件的html版本中调用Markdown::parse($slot) ,因为这是将Mardown解析为HTML来发送Markdown电子邮件的HTML版本的方法。 您正在查看Markdown组件。

我使用HTML电子邮件,实际上非常容易。

只需像您应该的那样创建一个可php artisan make:mail OrderShippedphp artisan make:mail OrderShipped )。 只需return $this->view('your.email.layout'); build()方法中。

your.email.layout就像使用普通刀片模板一样,执行@extend('your.email.master.layout') 执行@section('content')或您给它的任何名称,然后设计刀片模板。

如果您有任何困难,请告诉我。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM