Use composer to install the module.
composer require silverstripers/custom-emails
Define your emails first in YAML files and run a dev build. The emails objects will be created in the CMS (Siteconfig). You can have multiple emails defined with different identifiers.
Once you go in the CMS and configure them you can start sending emails.
---
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
###Sending emails
To send an email you can use the Processor classs.
use SilverStripers\CustomEmails\Model\NotificationEmail;
$processor = NotificationEmail::get_processor(
'EMAIL_IDENTIFIER',
'[email protected]',
'[email protected]',
[
'Name' => 'Name',
'Email' => '[email protected]'
]
);
$processor->setAttachments([
'file_name' => $content
]);
$processor->send();
The functions above can be used as this.
use SilverStripers\CustomEmails\Model\NotificationEmail;
NotificationEmail::get_processor('EMAIL_IDENTIFIER')
->setTo('[email protected]')
->setFrom('[email protected]')
->setData([]) // data as you specify on your merge tags
->setAttachments([
'file_name' => $content
])->send();