我在使用october的mail fascade来发送邮件。在文档中这样写道。
默认情况下,给发送方法的视图被认为是包含HTML的。然而,通过向发送方法传递一个数组作为第一个参数,你可以在HTML视图之外指定一个纯文本视图来发送。
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('[email protected]');
$message->subject('Test message');
});
我试了有无数组键的情况 第一个视图文件总是用于两个部分。我想,这是个bug。
在 https:/octobercms.comforumppostmail-with-plain-text-alternative。 mjauvin给出了一个对我有用的答案。
我不知道,但你可以在同一个视图文件中同时使用两种视图(纯文本和html)。
我相信数组中项目的顺序很重要。文档中说。
默认情况下,给发送方法的视图被假定为包含HTML。然而,通过传递一个数组作为发送方法的第一个参数,你可以在HTML视图之外指定一个纯文本视图来发送。
Mail::send(['acme.blog::mail.html', 'acme.blog::mail.text'], $data, $callback);
措辞表明,数组中的第一项将是 html
而第二种则是 text
. 即使它没有明确。
以防有人对上位者的回答感到困惑。邮件模板文件可以将标题、文本、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>