saskoh / conaktiv-emogrifyplugin
Inline CSS in HTML using Emogrifier.
Requires
- php: ^5.6 || ^7.0 || ^8.0
- pelago/emogrifier: ^5.0.1
Requires (Dev)
- phpunit/phpunit: ^5.7
- squizlabs/php_codesniffer: ^3
README
Inline CSS in HTML using Emogrifier.
Installation and requirements
Install via composer, using:
composer require saskoh/conaktiv-emogrifyplugin
Requirements:
- PHP 5.6+
- Emogrifier 3.x
Usage
By default, the plugin will inline CSS that is part of the HTML, eg. styles defined in <style>
tags.
You can instantiate the plugin with your own Emogrifier
instance or change properties of the emogrifier instance.
For a list of options, please head over to the Emogrifier documentation.
Please note, that the plugin is using one instance of Emogrifier
to convert all message-parts,
so the settings you make apply to all converted html parts.
Supplying custom CSS
$plugin = new EmogrifierPlugin(); $plugin->getEmogrifier()->setCss('.customStyle: { color: red; };');
Please note: Calling setHtml
on the Emogrifier instance doesn't have an effect, since it will be replaced with
the message body!
Example
Here's how you could use the plugin to send emails with custom styles loaded from a file:
$emogrifier = new Pelago\Emogrifier(); $emogrifier->setCss(file_get_contents( /* path to your CSS file */ ));