交叉连接 / 预邮件发送
此包已废弃且不再维护。未建议替代包。
Crossjoin\PreMailer将给定HTML源中的CSS转换为内联样式,并优化其通过电子邮件发送。它还创建了HTML源的文本版本。需要PHP 5.4以上版本。
v1.0.5
2015-12-26 15:44 UTC
Requires
- php: >=5.4.0
- ext-dom: *
- ext-mbstring: *
- crossjoin/css: ^1.0.3
- symfony/css-selector: ^2.7.1
This package is not auto-updated.
Last update: 2020-02-07 07:39:17 UTC
README
简介
Crossjoin\PreMailer将给定HTML源中的CSS转换为内联样式,并优化其通过电子邮件发送。它还创建了HTML源的文本版本。
安装
这是一个composer包。有关基本安装信息,请参阅composer网站。
将以下行添加到您的composer.json
文件中
{ "require": { "crossjoin/pre-mailer": "1.0.*" } }
功能
- 从HTML源中提取CSS
- 可以将CSS移动到HTML文档的主体中(这样一些电子邮件客户端就不会删除它)
- 可以删除HTML文档中的注释
- 可以删除HTML文档中的所有class属性
- 压缩CSS
- 创建HTML文档的文本版本(用于电子邮件的替代部分)
- ...
用法
读取HTML
您可以读取不同的HTML源。
// Read HTML file $htmlFileName = "path/to/file.html"; $preMailer = new \Crossjoin\PreMailer\HtmlFile($htmlFileName); // Read HTML string $htmlString = "<html>...</html>"; $preMailer = new \Crossjoin\PreMailer\HtmlString($htmlString);
设置字符集
默认字符集是"UTF-8"。您可以将其更改为首选字符集。
// Sets the charset of the HTML file. $preMailer->setCharset("ISO-8859-1");
设置选项
您可以设置不同的选项来影响PreMailer的行为。
// Remove HTML comments (default) $preMailer->setOption($preMailer::OPTION_HTML_COMMENTS, $preMailer::OPTION_HTML_COMMENTS_REMOVE); // Keep HTML comments $preMailer->setOption($preMailer::OPTION_HTML_COMMENTS, $preMailer::OPTION_HTML_COMMENTS_KEEP); // Move the style tag to the body of the HTML document (default) $preMailer->setOption($preMailer::OPTION_STYLE_TAG, $preMailer::OPTION_STYLE_TAG_BODY); // Move the style tag to the head of the HTML document $preMailer->setOption($preMailer::OPTION_STYLE_TAG, $preMailer::OPTION_STYLE_TAG_HEAD); // Remove the style tag from the HTML document // (to use, if ALL of your styles can be written inline) $preMailer->setOption($preMailer::OPTION_STYLE_TAG, $preMailer::OPTION_STYLE_TAG_REMOVE); // Keep HTML class attributes (default) $preMailer->setOption($preMailer::OPTION_HTML_CLASSES, $preMailer::OPTION_HTML_CLASSES_KEEP); // Remove HTML class attributes $preMailer->setOption($preMailer::OPTION_HTML_CLASSES, $preMailer::OPTION_HTML_CLASSES_REMOVE); // Set line-width of the text version (defaults to 75) $preMailer->setOption($preMailer::OPTION_TEXT_LINE_WIDTH, 60); // Set CSS writer class (class that extends \Crossjoin\Css\Writer\WriterAbstract). // By default the Compact writer (\Crossjoin\Css\Writer\Compact) is used, but for // some purposes another writer (like \Crossjoin\Css\Writer\Pretty) can be useful. $preMailer->setOption($preMailer::OPTION_CSS_WRITER_CLASS, $preMailer::OPTION_CSS_WRITER_CLASS_PRETTY); // Instead of the constant also the full class name can be used: $preMailer->setOption($preMailer::OPTION_CSS_WRITER_CLASS, '\Crossjoin\Css\Writer\Pretty'); // So you can use your own writer if required: $preMailer->setOption($preMailer::OPTION_CSS_WRITER_CLASS, '\MyNameSpace\Css\Writer\MyWriter');
生成内容
PreMailer生成了用于电子邮件的优化HTML和文本版本。
// Get the HTML version $html = $preMailer->getHtml(); // Get the text version $text = $preMailer->getText();
待办事项
- 添加字符集自动检测(从HTML文档中提取)
- 能够影响文本版本格式
- 优化内联样式(移除在相同内联样式中被覆盖的声明)