Carlos Goce Carlos Goce - 1 year ago 74
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) {
$html = View::make('email.notification', $viewData)->render();
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('', 'John Smith')->subject('Welcome!');

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

Answer Source

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('', 'John Smith')->subject('Welcome!'); });

Let me know how you get on.