yiisoft / yii-swiftmailer
3.0.1
2021-08-30 18:26 UTC
Requires
- php: ^7.4|^8.0
- swiftmailer/swiftmailer: ^6.2
- yiisoft/mailer: ^3.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- roave/infection-static-analysis-plugin: ^1.9
- spatie/phpunit-watcher: ^1.23
- vimeo/psalm: ^4.9
- yiisoft/files: ^1.0
- yiisoft/psr-dummy-provider: ^1.0
- yiisoft/test-support: ^1.3
README
此包已被弃用,推荐使用Symfony 邮件扩展。
请参阅 Fabien Potencier 的文章Swiftmailer 的终结中的详细说明。
❌
Yii 邮件库 - Swift Mailer 扩展
此包是yiisoft/mailer库的实现,提供了Swift Mailer邮件解决方案。
安装
可以使用composer安装此包
composer require yiisoft/mailer-swiftmailer --prefer-dist
通用用法
创建邮件发送者
use Yiisoft\Mailer\MessageBodyRenderer; use Yiisoft\Mailer\MessageBodyTemplate; use Yiisoft\Mailer\MessageFactory; use Yiisoft\Mailer\SwiftMailer\Mailer; use Yiisoft\Mailer\SwiftMailer\Message; /** * @var \Psr\EventDispatcher\EventDispatcherInterface $dispatcher * @var \Swift_Events_EventListener[] $plugins * @var \Swift_Transport $transport * @var \Yiisoft\View\View $view */ $template = new MessageBodyTemplate('/path/to/directory/of/view-files'); $mailer = new Mailer( new MessageFactory(Message::class), new MessageBodyRenderer($view, $template), $dispatcher, $transport, $plugins, // By default, an empty array );
发送邮件消息
$message = $mailer ->compose() ->withFrom('from@domain.com') ->withTo('to@domain.com') ->withSubject('Message subject') ->withTextBody('Plain text content') ->withHtmlBody('<b>HTML content</b>') ; $mailer->send($message); // Or several $mailer->sendMultiple([$message]);
Yiisoft\Mailer\SwiftMailer\Message
的额外方法
getSwiftMessage()
- 返回一个 Swift 消息实例。getReadReceiptTo()
- 返回将发送读取回执的地址。withReadReceiptTo()
- 返回一个新实例,该实例将根据指定地址请求发送回执。withAttachedSigners()
- 返回一个新实例,该实例具有指定的附加签名者。
有关在Yii 框架中使用,请参阅配置文件
有关更多信息,请参阅Yii 邮件指南。
测试
单元测试
此包使用PHPUnit进行测试。要运行测试
./vendor/bin/phpunit
变异测试
此包测试使用Infection变异框架和Infection 静态分析插件进行检查。要运行它
./vendor/bin/roave-infection-static-analysis-plugin
静态分析
使用Psalm对代码进行静态分析。要运行静态分析
./vendor/bin/psalm
许可
Yii 框架 Swift Mailer 扩展是免费软件。它根据 BSD 许可协议发布。请参阅 LICENSE
以获取更多信息。
由 Yii 软件 维护。