bummzack/swiftmailer-emogrifyplugin

使用Emogrifier在SwiftMailer的HTML输出中内联CSS。

1.0.1 2022-03-24 17:44 UTC

This package is auto-updated.

Last update: 2024-08-25 00:36:20 UTC


README

Scrutinizer Code Quality Code Coverage Build Status Latest Stable Version

使用Emogrifier在SwiftMailer的HTML输出中内联CSS。Emogrifier.

安装和需求

通过composer安装,使用

composer require bummzack/swiftmailer-emogrifyplugin

需求

  • PHP 7.2+
  • SwiftMailer 6.x
  • Emogrifier 6.x

使用方法

默认情况下,插件将内联HTML中的CSS,例如在<style>标签中定义的样式。

提供自定义CSS

$plugin = new EmogrifierPlugin();
$plugin->setCss('.customStyle: { color: red; };');

示例

以下是如何使用此插件发送从文件加载自定义样式的电子邮件的示例

$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);