Dynamically generate inline css styles for email templates in Symfony2 Dynamically generate inline css styles for email templates in Symfony2 symfony symfony

Dynamically generate inline css styles for email templates in Symfony2


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.


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.


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