atk4/outbox

敏捷工具箱 电子邮件

3.1.0 2022-01-28 08:46 UTC

This package is not auto-updated.

Last update: 2024-09-23 01:09:33 UTC


README

大多数网络应用程序都需要与用户通信。遵循以任务为中心的方法,此ATK插件实现了各种组件,以帮助与用户通信。

基本思想是避免错误,并提供使用组件的唯一方式。

如何安装

composer require atk4/outbox

如何与 Atk4/Ui 一起使用

在调用 $app->initLayout() 之后添加以下行

$app->add([Outbox::class, [
    'mailer' => new Sendmail(),
    'model' => new Mail($this->db),
]]);

之后,您可以从任何视图调用 $this->getApp()->getOutbox()

如何在不使用 Atk4/Ui 的情况下使用

添加以下代码

$outbox = new Outbox([
    'mailer' => new Sendmail(),
    'model' => new Mail($this->db),
]);

由于缺少 App,初始化未调用,因此您必须自行运行它

$outbox->invokeInit(); 

邮件发送器 (PHMailer)

  • Sendmail
  • Gmail
    • 可以使用 Atk4 直接注入进行自定义
      • 用户名
      • 密码
  • SMTP
    • 可以使用 Atk4 直接注入进行自定义
      • debug = PHPMailer::DEBUG_OFF;
      • auth = false
      • host = 'localhost';
      • port = 587;
      • secure = PHPMailer::ENCRYPTION_*
      • 用户名
      • 密码

扩展邮件发送器

无论您的需求是什么,您都必须仅尊重 MailerInterface 接口提供的协议。因此,任何传统的 SMTP 或 API SMTP 都可以通过创建一个新的类并定义方法 : send(Mail $mail): MailResponse 来添加,在初始化期间添加到 Outbox 并使用它。

如果您创建了一个新的邮件发送器,请随时提交一个 PR。

如何使用它

// request an new email from outbox  
$mail = $outbox->new();

// use an already saved mail template
$mail->withTemplateIdentifier('template_test');

// replace token with data
$mail->replaceContent('token', 'Agile Toolkit');

// Add a custom address as "to"
$mail->ref('to')->createEntity()->save([
    'email' => 'destination@email.it',
    'name' => 'destination',
]);

// send the mail and check the response 
$response = $outbox->send($mail);

待办事项

  • 在模板中存储存在于字段中的令牌(目前,只有一个草案)
  • 向邮件模板添加更多助手或创建一个控制器来操作它,使其更简单,仅作为描述符
  • 添加 wysiwyg 编辑器以编辑单个模板(UI)
  • 添加失败消息的重发系统
  • 发送短信
  • 如果您有更多想法,请随时提交一个问题