saskoh/conaktiv-emogrifyplugin

Inline CSS in HTML using Emogrifier.

0.3.2 2021-04-07 10:36 UTC

This package is auto-updated.

Last update: 2024-05-07 18:00:49 UTC


README

Scrutinizer Code Quality Code Coverage Build Status Latest Stable Version

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 */ ));