Reputation: 5627
I'm trying to send emails in laravel5.1 and found that Mail:Send used view templates like below:
Mail::send(['html.view', 'text.view'], $data, $callback);
Problem is I have my ready to send HTML body and TEXT body are coming from database. How to set html view and text view if content coming from database like below:
$html_body = $row['Html_Body']; // holds html content
$text_body = $row['Text_Body']; // holds text content
Thanks.
Upvotes: 1
Views: 1536
Reputation: 5627
To attach text/plain message we can use addParts method like below
$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');
Upvotes: 0
Reputation: 36
$mailBody = View::make('my_mail', ['name' => 'fknight']);
$contents = (string) $mailBody;
// or
$contents = $mailBody->render();
this is the better way instead of using plain html in variable
Upvotes: 0
Reputation: 971
you can pass your data to your view like this
$data = [];
$data['Html_Body'];
$data['Text_Body'];
\Mail::send('html.view', $data , function($message)
{
$message->to($email)->subject($subject);
});
and use the data you passed to the view as variables
$Html_Body;
$Text_Body;
Upvotes: 0
Reputation: 356
you can use :
Mail::send(['text' => $text_body], $data, $callback);
Upvotes: 1