miniframe / mailer-bundle
Miniframe PHP 框架的邮件插件。
v1.0.1
2021-09-20 11:18 UTC
Requires
- php: >=7.3
- miniframe/core: ^1.0
- phpmailer/phpmailer: ^6.5
Requires (Dev)
- garrcomm/phpunit-helpers: ^1.0
- phpunit/phpunit: ^9.4
- squizlabs/php_codesniffer: ^3.5
Suggests
- ext-fileinfo: To automatically detect the mime type for mail attachments
README
这是 Miniframe PHP 框架的邮件插件。
使用此插件,您可以在 PHP 应用程序中轻松设置发送邮件。
如何使用
- 在现有项目中,输入:
composer require miniframe/mailer-bundle
- 将以下指令添加到您的 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.bat、bin\phpcs.bat、bin\phpunit.bat、bin\phpstan.bat 和 bin\security-checker.bat 作为 Composer、CodeSniffer、PHPUnit、PHPStan 和安全检查器的快捷方式,无需在您的计算机上安装 PHP 和其他依赖项。
在 Bitbucket Pipelines 中使用相同的 Docker 容器和工具来自动测试此项目。