vaszloy / yii2-email-manager
Yii2 邮件管理器
0.4.2
2023-10-30 22:17 UTC
Requires
- php: >=8.2
- mailgun/mailgun-php: ^v3
- php-http/guzzle7-adapter: ^1.0
- yiisoft/yii2: ~2.0
Suggests
- cboden/ratchet: to use loop instead of for-cycle in daemon
This package is not auto-updated.
Last update: 2024-10-01 02:43:01 UTC
README
安装
简单配置
'components' => [
'emailManager' => [
'class' => '\yarcode\email\EmailManager',
'transports' => [
'yiiMailer' => '\yarcode\email\transports\YiiMailer'
],
],
]
多传输配置
'components' => [
'emailManager' => [
'class' => '\yarcode\email\EmailManager',
'defaultTransport' => 'yiiMailer',
'transports' => [
'yiiMailer' => [
'class' => '\yarcode\email\transports\YiiMailer',
],
'mailGun' => [
'class' => '\yarcode\email\transports\MailGun',
'apiKey' => 'xxx',
'domain' => 'our-domain.net',
],
],
],
]
将命令添加到可用的命令列表中。将其放入控制台应用程序配置中
'controllerMap' => [
'email' => '\yarcode\email\commands\EmailCommand',
],
通过lockrun或run-one工具将邮件发送守护进程添加到crontab
*/5 * * * * run-one php /your/site/path/yii email/run-spool-daemon
或者,如果您将使用cboden/ratchet
*/5 * * * * run-one php /your/site/path/yii email/run-loop-daemon
用法
// obtain component instance
$emailManager = EmailManager::geInstance();
// direct send via default transport
$emailManager->send('from@example.com', 'to@example.com', 'test subject', 'test email');
// queue send via default transport
$emailManager->send('from@example.com', 'to@example.com', 'test subject', 'test email');
// direct send via selected transport
$emailManager->transports['mailGun']->send('from@example.com', 'to@example.com', 'test subject', 'test email');
// use shortcuts
EmailTemplate::findByShortcut('shortcut_name')->queue('recipient@email.org', ['param1' => 1, 'param2' => 'asd']);