I am attempting to send an HTML email from a symfony (1.4.6) task, I don’t want to send the entire rendered HTML output from a particular module/action, so I am rendering a partial. That’s all fine, the issue is that the partial contains CSS references.
Is there a nice ‘symfonic’ way of including a CSS file in an HTML email from a symfony task, when all I am doing is rendering a specific partial? Or is the only solution to build the HTML head/body manually inside the task, using file_get_contents(cssFile) to grab the CSS file and then concatenating the rendered partial?
Any thoughts would be appreciated.
I ran into the same problem in my project. Here’s how I fixed it:
To keep the CSS separate but get it inline before sending the email, we use Emogrifier. Download the source code and put it into
%sf_lib_dir%/vendor/emogrifier.Create a myMailer class that extends sfMailer. Mine is below. There are a few separate functions, but the key function is
composeAndSendPartial, which takes a partial name (as a string), inserts all the CSS inline, and sends it. I tried to remove all code that’s specific to my project, but I may have left some in. Let me know if it doesn’t work for you or if you have any questions.In factories.yml, set the
mailer:tomyMailermyMailer.class.php: