stocker4all / swift-html-image
此包已被废弃,不再维护。未建议替代包。
在 Swift Mailer 消息体 html 中嵌入图像
v0.3
2017-10-31 14:31 UTC
Requires
- php: >=7.1
- swiftmailer/swiftmailer: >=5.4.8
Requires (Dev)
- phpunit/phpunit: ^6.4
This package is not auto-updated.
Last update: 2024-01-24 20:10:41 UTC
README
swift-html-image
是一个简单的方法,用于在 html 中自动嵌入相对路径的图像源,以便在 Swift Mailer 消息中进一步使用。
例如
<html> <title>stocker4all/swift-html-image</title> <body> <h1>swift-html-image</h1> <img src = "img/example.jpg"> <img src = "//example.com/example.jpg"> <img src = "http://example.com/example.jpg"> <img src = "https://example.com/example.jpg"> </body> </html>
将被转换成类似以下内容
<html> <title>swift-html-image</title> <body> <h1>swift-html-image</h1> <img src="cid:cbb8136c77eade53667df53661e2a973@localhost"> <img src="//example.com/example.jpg"> <img src="http://example.com/example.jpg"> <img src="https://example.com/example.jpg"> </body> </html>
注意,只有带有相对路径的图像已成为源 cid
值。
如果找不到带有相对路径的图像,将抛出 SwiftHtmlImageException
。
安装
{ "require": { "stocker4all/swift-html-image": "~0.3" } }
使用示例
$html = '<!-- Your HTML goes here -->'; $swiftMessage = new Swift_Message(); $swiftHtmlImage = new S4A\SwiftHtmlImage( '/path-to-your-image-root-folder' ); $swiftMessage->setBody( $swiftHtmlImage->embedImages($swiftMessage, $html), "text/html", "utf-8");
测试
在 tests/
目录中提供了一些非常基本的测试。使用 composer install --dev && vendor/bin/phpunit
运行它们。
许可证
swift-html-image
在 MIT 许可下发布