Laravel 5.1:如何在不使用视图的情况下传递HTML正文和文本正文?

时间:2016-05-30 08:04:14

标签: php laravel laravel-5.1 html-email sendmail

我尝试在laravel5.1中发送电子邮件,发现Mail:发送使用过的视图模板如下:

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

问题是我已准备好发送HTML正文和TEXT正文来自数据库。如果来自数据库的内容如下所示,如何设置html视图和文本视图:

$html_body = $row['Html_Body']; // holds html content
$text_body = $row['Text_Body']; // holds text content

感谢。

4 个答案:

答案 0 :(得分:1)

你可以使用:

Mail::send(['text' => $text_body], $data, $callback);

答案 1 :(得分:0)

您可以将数据传递到您的视图

$data = [];
$data['Html_Body'];
$data['Text_Body'];
\Mail::send('html.view', $data , function($message)
{
    $message->to($email)->subject($subject);
});

并将您传递给视图的数据用作变量

$Html_Body;
$Text_Body;

答案 2 :(得分:0)

    $mailBody = View::make('my_mail', ['name' => 'fknight']);
    $contents = (string) $mailBody;
    // or
    $contents = $mailBody->render();

这是更好的方式,而不是在变量

中使用普通的html

答案 3 :(得分:0)

要附加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');