yiisoft/yii-swiftmailer

此包已被废弃,不再维护。作者建议使用yiisoft/mailer包。

Yii 邮件库 - Swift Mailer 扩展

3.0.1 2021-08-30 18:26 UTC

This package is auto-updated.

Last update: 2022-06-01 11:08:46 UTC


README

此包已被弃用,推荐使用Symfony 邮件扩展

请参阅 Fabien Potencier 的文章Swiftmailer 的终结中的详细说明。

68747470733a2f2f796969736f66742e6769746875622e696f2f646f63732f696d616765732f7969695f6c6f676f2e737667 68747470733a2f2f73776966746d61696c65722e73796d666f6e792e636f6d2f696d616765732f6c6f676f2e706e67

Yii 邮件库 - Swift Mailer 扩展


Latest Stable Version Total Downloads Build status Scrutinizer Code Quality Code Coverage Mutation testing badge static analysis type-coverage

此包是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 软件 维护。

支持项目

Open Collective

关注更新

Official website Twitter Telegram Facebook Slack