Mailblade is a Laravel plugin that lets you manage your email templates in Laravel easily and without hassle.
You can use the powerful Blade templating engine inside your emails for your html templates.
IMPORTANT: For the text version of the templates we stick with regular php.
Via Laravel's very own artisan tool:
php artisan bundle:install mailblade
Go into you application/bundles.php
file and add this line to your bundles array:
'mailblade' => array('auto' => true)
Mailblade is usable out of the box.
You handle it as you handle any view in Laravel:
$message = Mailblade::make('password-restore');
$message->with('email', '[email protected]')
$message->with('key', 'Fhgns7396&-21dj');
Or even like this:
$input = array(
'email' => '[email protected]',
'key' => 'Fhgns7396&-21dj'
);
$message = Mailblade::make('password-restore', $input);
To see the html version of a template simply do:
$html = Mailblade->html();
For the text version:
$txt = Mailblade->text();
Mailblade views are different to your 'regular' Laravel Views in two ways:
- You choose the default folder for your templates.
- They are language-aware
Let us explain...
By default, Mailblade chooses your email template from the mailblade/views
folder.
You can choose any folder you want for your template files by going into mailblade/config/options.php
file.
Mailblade chooses the appropriate template based on your application language.
Make sure you follow this convention when placing your files:
[template_dir]/[language]/[template_name].blade.php
So, for example, the english version of the 'contact-message' template sould be placed like this:
mailblade/templates/en/contact-message
The best thing about Mailblade is that it comes with templates for sending commonly used email messages, like:
- Contact form
- Password restore
- User confirmations
You can even preview the messages if you do something like this in your routes files:
Route::get('preview', function()
{
return Mailblade::make('your-template')->html();
}
Or for the text version
Route::get('preview', function()
{
return Mailblade::make('your-template')->text();
}
Note: (Templates are on the way and will be pushed soon)