2017 © Pedro Peláez
 

library swiftmailer-emogrifyplugin

Inline CSS in the HTML output of SwiftMailer using Emogrifier.

image

bummzack/swiftmailer-emogrifyplugin

Inline CSS in the HTML output of SwiftMailer using Emogrifier.

  • Saturday, February 17, 2018
  • by bummzack
  • Repository
  • 1 Watchers
  • 0 Stars
  • 63 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 142 % Grown

The README.md

Swift Mailer Emogrify Plugin

Scrutinizer Code Quality Code Coverage Build Status Latest Stable Version, (*1)

Inline CSS in the HTML output of SwiftMailer using Emogrifier., (*2)

Installation and requirements

Install via composer, using:, (*3)

composer require bummzack/swiftmailer-emogrifyplugin

Requirements:, (*4)

  • PHP 5.6+
  • SwiftMailer 5.x
  • 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., (*5)

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., (*6)

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!, (*7)

Example

Here's how you could use the plugin to send emails with custom styles loaded from a file:, (*8)

$emogrifier = new Pelago\Emogrifier();
$emogrifier->setCss(file_get_contents( /* path to your CSS file */ ));

// Create the Mailer using any Transport
$mailer = new Swift_Mailer(
    new Swift_SmtpTransport('smtp.example.org', 25)
);

// Use Emogrifier plugin to inline styles. You can pass the emogrifier instance as a parameter
$mailer->registerPlugin(new Bummzack\SwiftMailer\EmogrifyPlugin\EmogrifierPlugin($emogrifier));

$message = new Swift_Message();
$message
    ->setSubject('Your subject')
    ->setFrom(['test@example.com' => 'Test'])
    ->setTo(['receiver@example.com'])
    ->setBody('

My custom HTML, (*9)

', 'text/html'); // Send your email $mailer->send($message);

The Versions

17/02 2018

dev-master

9999999-dev

Inline CSS in the HTML output of SwiftMailer using Emogrifier.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

plugin swiftmailer emogrifier

16/02 2018

0.1

0.1.0.0

Inline CSS in the HTML output of SwiftMailer using Emogrifier.

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

plugin swiftmailer emogrifier