If Only I Knew That!

Webby things that could save you time

Send plain text email with Laravel 4

without comments

Laravel 4 takes the view and parses it and sends it as HTML

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

But what if you want to send HTML and plain text? Laravel makes that easy you need to use an array

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

But want if I just want to send just plain text. Once again Laravel has a simple solution. You need to use an associative array. This isn’t or wasn’t documented but all you have to do is look in the source.

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

The opposite key is ‘html’

Written by admin

September 17th, 2013 at 9:23 am

Posted in Laravel

Leave a Reply

Powered by CDN Rewrites