Carlos Goce Carlos Goce - 5 months ago 19
PHP Question

Sending e-mail in Laravel with custom HTML

I need to send e-mails but I already have the HTML generated, I don't want to use laravel blade because I need to apply a CSS Inliner to the HTML, so this is how i generate the html:

getRenderedView($viewData) {
//code
$html = View::make('email.notification', $viewData)->render();
$this->cssInliner->setCSS($this->getCssForNotificationEmail());
$this->cssInliner->setHTML($html);
return $this->cssInliner->convert();
}


So, to send the mail with Laravel you usually do something like this:

Mail::send('emails.welcome', $data, function($message)
{
$message->to('foo@example.com', 'John Smith')->subject('Welcome!');
});


But I don't want to pass a view, I already have the html, how can I do that?

Answer

If I'm right in what you want to achieve, to get round this I created a view called echo.php and inside that just echo $html.

Assign your html to something like $data['html'].

Then below pass your $data['html'] to the echo view.

Mail::send('emails.echo', $data, function($message) { $message->to('foo@example.com', 'John Smith')->subject('Welcome!'); });

Let me know how you get on.

Comments