Support the ongoing development of Laravel.io →
IOC Views Mail
Last updated 2 years ago.
0

What an active community!

Last updated 2 years ago.
0

Hi ammont.

I was recently looking into the same thing. Check out this package: https://github.com/fedeisas/laravel-mail-css-inliner

It will create a plugin for swiftmail (the underlining library for Laravel's mail component) that will inline your CSS.

It does make sending mail (even) slower, so you might want to consider using Laravel's queue feature.

Hope that's what you're looking for.

Tom

Last updated 2 years ago.
0

The laravel inliner linked above didn't work as expected. It has huge issues working with multiple CSS rules for the same elements and media queries. Premailer works much better for me. I found a PHP lib which executes Ruby code (Premailer is ruby gem).

I created a simple laravel wrapper for it, you can get it here: https://packagist.org/packages/emil/inliner

Inliner::view('emails.templates.newsletter');
Inliner::argument('include_style_tags', true);
Inliner::argument('preserve_styles', true);
$body = Inliner::getConvertedHtml();

Mail::send('data', array('data' => $body), function($message)
{
	$message->to('[email protected]', 'John Smith')->subject('Welcome!');
});

Note: data.blade.php is just a dummy view with the following code (is there a better way to do this?)

{{ $data }}
Last updated 2 years ago.
0

Hi!

@emilsundberg, I'm trying to use your inliner library, but I have some questions,

When I call a method, e.g. Inliner::view, I get the error

Call to undefined method Emil\Inliner\Inliner::view()

I added Inliner as a service provider in my config/app.php, but should I have to add it as a class alias in that file?

If my template has dynamic data, could I call the method as

$data = array('name' => $user->name, 'language' => 'en');		
Inliner::view('emails.welcome', $data);

to fill my custom variables in the template?

Thank you in advance! ;)

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ammont ammont Joined 10 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.