Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically generate inline css styles for email templates in Symfony2

Is there a tool or a bundle in Symfony2 that allows me to create normal templates with css files, and then on the fly convert it to inline css rules so it can be used as the body of an email?

like image 830
David Barreto Avatar asked Sep 05 '12 23:09

David Barreto


3 Answers

I know of three tools that can do this and which you can use in Symfony:

  • Premailer is an online tool which provides this service. It has an API and a php wrapper for that API
  • CssToInlineClass is a php class that offers this functionality
  • Mailchimp offers a function in their api that offers this functionality

The first two don´t have a direct symfony implementation, though they will be easy to use. For mailchimp, there is a mailchimp bundle which offers this functionality, though the bundle is not very well documented.

like image 111
Carlos Granados Avatar answered Oct 12 '22 23:10

Carlos Granados


Today I discovered through another question that exists such a Symfony2 bundle that fits your needs (I didn't tested it).

You can use ToInlineStyleEmailBundle, it embeds the CSSToInline library that Carlos Granados suggested in his answer.

With this Symfony2 bundle you can get the converter as a service ($this->get('css_to_inline_email_converter')) and then use it for your needs. It also supports templates generations.

like image 32
JeanValjean Avatar answered Oct 13 '22 00:10

JeanValjean


I've had great results with integrating the Emogrifier PHP class within CakePHP. Inlines all styles very nicely. Not sure if it has a Symfony bundle but shouldn't be hard to integrate.

https://github.com/jjriv/emogrifier

like image 29
Simon East Avatar answered Oct 13 '22 01:10

Simon East