bummzack / swiftmailer-emogrifyplugin
Inline CSS in the HTML output of SwiftMailer using Emogrifier.
Installs: 21 781
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 3
Open Issues: 0
Requires
- php: ^7.2 || ^8.0
- pelago/emogrifier: ^6.0
- swiftmailer/swiftmailer: ^6.0
Requires (Dev)
- mockery/mockery: 1.3.5
- phpunit/phpunit: ^8.5
- squizlabs/php_codesniffer: ^3
README
Inline CSS in the HTML output of SwiftMailer using Emogrifier.
Installation and requirements
Install via composer, using:
composer require bummzack/swiftmailer-emogrifyplugin
Requirements:
- PHP 7.2+
- SwiftMailer 6.x
- Emogrifier 6.x
Usage
By default, the plugin will inline CSS that is part of the HTML, eg. styles defined in <style>
tags.
Supplying custom CSS
$plugin = new EmogrifierPlugin(); $plugin->setCss('.customStyle: { color: red; };');
Example
Here's how you could use the plugin to send emails with custom styles loaded from a file:
$plugin = new Bummzack\SwiftMailer\EmogrifyPlugin\EmogrifierPlugin(); $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. $mailer->registerPlugin($plugin); $message = new Swift_Message(); $message ->setSubject('Your subject') ->setFrom(['test@example.com' => 'Test']) ->setTo(['receiver@example.com']) ->setBody('<p>My custom HTML</p>', 'text/html'); // Send your email $mailer->send($message);