Laravel 5.1: 如何在不使用视图的情况下传递 HTML Body 和 Text Body?
Laravel 5.1: How to pass HTML Body and Text Body without using view?
我正在尝试在 laravel5.1 中发送电子邮件,发现 Mail:Send 使用如下视图模板:
Mail::send(['html.view', 'text.view'], $data, $callback);
问题是我已准备好发送 HTML 正文和文本正文来自数据库。如果内容来自如下数据库,如何设置 html 视图和文本视图:
$html_body = $row['Html_Body']; // holds html content
$text_body = $row['Text_Body']; // holds text content
谢谢。
您可以使用:
Mail::send(['text' => $text_body], $data, $callback);
您可以像这样将数据传递到您的视图
$data = [];
$data['Html_Body'];
$data['Text_Body'];
\Mail::send('html.view', $data , function($message)
{
$message->to($email)->subject($subject);
});
并将您传递给视图的数据用作变量
$Html_Body;
$Text_Body;
$mailBody = View::make('my_mail', ['name' => 'fknight']);
$contents = (string) $mailBody;
// or
$contents = $mailBody->render();
这是比在变量
中使用普通 html 更好的方法
要附加 text/plain 消息,我们可以使用如下所示的 addParts 方法
$message->to($email_details['to'])
->subject($email_details['subject'])
->from($email_details['from'])
->setBody($email_details['html'], 'text/html');
/* add alternative parts with addPart()*/
$message->addPart($email_details['text'], 'text/plain');
我正在尝试在 laravel5.1 中发送电子邮件,发现 Mail:Send 使用如下视图模板:
Mail::send(['html.view', 'text.view'], $data, $callback);
问题是我已准备好发送 HTML 正文和文本正文来自数据库。如果内容来自如下数据库,如何设置 html 视图和文本视图:
$html_body = $row['Html_Body']; // holds html content
$text_body = $row['Text_Body']; // holds text content
谢谢。
您可以使用:
Mail::send(['text' => $text_body], $data, $callback);
您可以像这样将数据传递到您的视图
$data = [];
$data['Html_Body'];
$data['Text_Body'];
\Mail::send('html.view', $data , function($message)
{
$message->to($email)->subject($subject);
});
并将您传递给视图的数据用作变量
$Html_Body;
$Text_Body;
$mailBody = View::make('my_mail', ['name' => 'fknight']);
$contents = (string) $mailBody;
// or
$contents = $mailBody->render();
这是比在变量
中使用普通 html 更好的方法要附加 text/plain 消息,我们可以使用如下所示的 addParts 方法
$message->to($email_details['to'])
->subject($email_details['subject'])
->from($email_details['from'])
->setBody($email_details['html'], 'text/html');
/* add alternative parts with addPart()*/
$message->addPart($email_details['text'], 'text/plain');