silverstripers / custom-emails
从 Silverstripe 发送完全可定制的自定义电子邮件
dev-master
2024-09-05 09:17 UTC
Requires
- php: >=7.4|>=8
- silverstripe/framework: 4.* | 5.*
- silverstripers/grid-field-switch: *
This package is auto-updated.
Last update: 2024-09-05 09:17:19 UTC
README
安装
使用 composer 安装模块。
composer require silverstripers/custom-emails
配置
首先在 YAML 文件中定义您的电子邮件,然后运行开发构建。电子邮件对象将在 CMS(站点配置)中创建。您可以定义多个具有不同标识符的电子邮件。
一旦您进入 CMS 并进行配置,就可以开始发送电子邮件。
---
name: notifications-config
---
SilverStripers\CustomEmails\Dev\Injector:
definitions:
EMAIL_IDENTIFIER:
name: 'Title of the email'
dynamic: true # for emails which doesnt need a to address
template: '' # Silverstripe template file to use when rendering emails.
arguments: # merge tags
- Name
- Email
###发送电子邮件
要发送电子邮件,可以使用 Processor 类。
use SilverStripers\CustomEmails\Model\NotificationEmail;
$processor = NotificationEmail::get_processor(
'EMAIL_IDENTIFIER',
'to@email.com',
'from@email.com',
[
'Name' => 'Name',
'Email' => 'test@test.com'
]
);
$processor->setAttachments([
'file_name' => $content
]);
$processor->send();
上述函数可以用作这样。
use SilverStripers\CustomEmails\Model\NotificationEmail;
NotificationEmail::get_processor('EMAIL_IDENTIFIER')
->setTo('to@email.com')
->setFrom('from@email.com')
->setData([]) // data as you specify on your merge tags
->setAttachments([
'file_name' => $content
])->send();