如何使用来自 octobercms 的纯文本替代方案正确发送 Html-mail?

How to properly send Html-mail with plain text alternative from octobercms?

我正在使用 october 的邮件 fascade 发送电子邮件。在文档中写道:

By default, the view given to the send method is assumed to contain HTML. However, by passing an array as the first argument to the send method, you may specify a plain text view to send in addition to the HTML view:

Mail::send(['acme.blog::mail.html', 'acme.blog::mail.text'], $data, $callback);

但是当我这样做时,mail.text 视图文件被忽略了。对于消息的纯文本部分,还使用了 mail.html 视图文件,在换行符之前包含 <br />

我错过了什么吗?或者这是一个错误?

我的代码:

$vars = ['msg' => 'Hello world'];

Mail::send(
    ['text' => 'respective.test::mails.text', 
     'html' => 'respective.test::mails.html'],  
    $vars, function($message) { 
        $message->to('name@example.com'); 
        $message->subject('Test message');
    });

我尝试了使用和不使用数组键。第一个视图文件始终用于两个部分。我认为,这是一个错误。

https://octobercms.com/forum/post/mail-with-plain-text-alternative 上,mjauvin 给出了一个对我有用的答案:

I don't know but you can have both views (plain text and html) in the same view file.

我相信数组中项目的顺序很重要。文档说:

By default, the view given to the send method is assumed to contain HTML. However, by passing an array as the first argument to the send method, you may specify a plain text view to send in addition to the HTML view: Mail::send(['acme.blog::mail.html', 'acme.blog::mail.text'], $data, $callback);

措辞表明数组中的第一项为 html,第二项为 text。尽管它不是明确的。


以防有人对 OP 的回答感到困惑。邮件模板文件可以在一个文件中包含 header、文本、html,并以 == 分隔。

subject = "Your product has been added to OctoberCMS project"
==

Hi {{ name }},

Good news! User {{ user }} just added your product "{{ product }}" to a project.

This message was sent using no formatting (plain text)
==

<p>Hi {{ name }},</p>

<p>Good news! User {{ user }} just added your product <strong>{{ product }}</strong> to a project.</p>

<p>This email was sent using formatting (HTML)</p>