CakephpEmogrifierPlugin is a CakePHP 2.x Plugin that makes of using Emogrify on your HTML output easy.
Wondering what Emogrify is? Emogrifier is a great library from Pelago that deals with much of the hassle involved with HTML formatted email messages:-
This Plugin is a wrapper around Emogrifier making it easy to use in CakePHP 2.0x
Copy or symlink CakephpEmogrifierPlugin into a path named Emogrifier in your Plugin path like this:-
%APP%/Plugin/Emogrifier
Take careful note of the Plugin pathname, the name is "Emogrifier", not EmogrifierPlugin or CakephpEmogrifierPlugin, it's just Emogrifier. I spell this out because it's an easy thing to trip up on especially if your pulling this down from github or unpacking from a tarball.
Update the Emogrifier library from https://github.com/jjriv/emogrifier into the Vendor path of CakephpEmogrifierPlugin
cd %APP%/Plugin/Emogrifier/Vendor
git clone https://github.com/jjriv/emogrifier
NB: the Emogrifier.php that ships with CakephpEmogrifierPlugin will only be used if you do not clone in the latest from https://github.com/jjriv/emogrifier
NB2: it is safe to remove %APP%/Plugin/Emogrifier/Vendor/Emogrifier.php after you have cloned the latest https://github.com/jjriv/emogrifier to make it available to the CakephpEmogrifierPlugin plugin
Be sure to load the plugin in your bootstrap.php or core.php, like this:-
CakePlugin::load('Emogrifier');
If you adjust the bootstrap.php in config for CakephpEmogrifierPlugin you will need to make sure it gets parsed like this:-
CakePlugin::loadAll(array(
'Emogrifier' => array('bootstrap' => true)
));
The alternative is to note the Configure::write() options and set these from your own application bootstrap.php
Tell CakeEmail to Emogrify the HTML rendering by calling viewRender()
$email = new CakeEmail();
$email->viewRender('Emogrifier.Emogrifier');
$email->emailFormat('html');
$email->send('hello world');
Tell your controller to render your view with Emogrifier like this:-
$this->viewClass = 'Emogrifier.Emogrifier';
Q: Pelago's Emogrifier class requires you to pass in the CSS but this plugin does not, what's going on? A: We parse the HTML from the View->output attribute looking for CSS from link and style elements then stich the whole thing together - it makes using this a little easier.
Q: I'm using Emogrifier before rendering to webpages and I can't see any difference A: Take a look at the HTML source, you should notice that all your CSS styles are now inline element style attributes.
Q: I want to use a custom (forked) Emogrifier.php how can I do that? A: Take a look at Configure::write('Emogrifier.include','/foo/bar/Emogrifier.php');