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?
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.
4 Comments
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.
Comments
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.