locomotivemtl/charcoal-email

为 Charcoal 发送和排队电子邮件

0.7.2.1 2021-12-15 22:21 UTC

README

发送电子邮件(使用 PHPMailer)和队列管理。

如何安装

安装 charcoal-email 的首选(且唯一支持的)方式是使用 composer

★ composer require locomotivemtl/charcoal-email

依赖项

可选依赖项

👉 所有可选依赖项在开发中都是必需的。本README文件“开发”部分描述了当在项目中使用charcoal-email时,所有其他可选的开发依赖项。

用法

$email = $container['email'];
$email->setData([
    'campaign' => 'Campaign identifier'
    'to' => [
        'recipient@example.com',
        '"Some guy" <someguy@example.com>',
        [
            'name'  => 'Other guy',
            'email' => 'otherguy@example.com'
        ]
    ],
    'bcc' => 'shadow@example.com'
    'from' => '"Company inc." <company.inc@example.com>',
    'reply_to' => [
        'name' => 'Jack CEO',
        'email' => 'jack@example.com'
    ],
    'subject' => $this->translator->trans('Email subject'),
    'template_ident' => 'foo/email/default-email'
    'attachments' => [
        'foo/bar.pdf',
        'foo/baz.pdf'
    ]
]);
$email->send();

// Alternately, to send at a later date / use the queue system:
$email->queue('in 5 minutes');

电子邮件配置

整个电子邮件系统都可以通过主应用程序配置中的email配置键进行配置。

{
    "email": {
        "smtp": true,
        "smtp_hostname": "smtp.example.com",
        "smtp_port": 25,
        "smtp_security": "tls",
        "smtp_username": "user@example.com",
        "smtp_password": "password",

        "default_from": "webproject@example.com",
        "default_reply_to": "webproject@example.com",
        "default_track": false,
        "default_log": true
    }
}

服务提供商

所有电子邮件服务都可以通过\Charcoal\Email\ServiceProvider\EmailServiceProvider快速注册到(pimple)容器中。

提供的服务

1 \Charcoal\Email\Email.
2 Charcoal\Factory\FactoryInterface.

以下是一些辅助工具

3 \Charcoal\Email\EmailConfig.
4 \Charcoal\View\ViewInterface.

👉 对于 Charcoal 项目,只需将此提供程序添加到您的配置中即可启用

{
  "service_providers": {
      "charcoal/email/service-provider/email": {}
  }
}

服务依赖项

为了使 email 服务提供商正常工作,以下服务预期将在同一容器上注册

  • 配置
  • 视图

开发

安装开发环境

★ composer install --prefer-source

运行脚本(phplint、phpcs 和 phpunit)

★ composer test

开发依赖项

  • phpunit/phpunit
  • squizlabs/php_codesniffer
  • satooshi/php-coveralls

持续集成

编码风格

Charcoal-Email 模块遵循 Charcoal 编码风格

可以使用 composer phpcs 执行编码风格验证/强制执行。还有可用的自动修复程序,使用 composer phpcbf

作者

许可证

Charcoal 在 MIT 许可证下发布。有关详细信息,请参阅 LICENSE