miniframe/mailer-bundle

Miniframe PHP 框架的邮件插件。

v1.0.1 2021-09-20 11:18 UTC

This package is auto-updated.

Last update: 2024-09-25 23:54:22 UTC


README

这是 Miniframe PHP 框架的邮件插件。

使用此插件,您可以在 PHP 应用程序中轻松设置发送邮件。

build code coverage

如何使用

  1. 在现有项目中,输入: composer require miniframe/mailer-bundle
  2. 将以下指令添加到您的 config.ini

示例 config.ini 指令

[framework]
middleware[] = Miniframe\Mailer\Middleware\Mailer

[mailer]
from_name = Sender name
from_email = no-reply@foobar.baz
; Optionally, to use SMTP:
transport = smtp
smtp_hostname = smtp.foobar.baz
smtp_authentication = true
smtp_username = foobar
smtp_port = 587
; SMTP encryption can be TLS, SSL or PLAIN
smtp_encryption = TLS

将密码放置在单独的 secrets.ini 文件中,并将其添加到 .gitignore 文件中

[mailer]
smtp_password = ************************

现在,您可以在代码中使用它

$recipient = new Recipient('email@example.com', 'Example');
$subject = 'Mail subject';
$mailBody = new Response('<html lang="en"><body><b>HTML</b> mail</body></html>');

$mailer = Registry::get(Mailer::class);
$mailer->sendMail($recipient, $subject, $mailBody);

针对 Windows 开发者

bin 文件夹中,有几个批处理文件,可以使开发更简单。

如果您安装了 Docker Desktop for Windows,则可以使用 bin\composer.batbin\phpcs.batbin\phpunit.batbin\phpstan.batbin\security-checker.bat 作为 Composer、CodeSniffer、PHPUnit、PHPStan 和安全检查器的快捷方式,无需在您的计算机上安装 PHP 和其他依赖项。

Bitbucket Pipelines 中使用相同的 Docker 容器和工具来自动测试此项目。