Adds an easy way to create email templates in SilverStripe CMS
- PHP 70.1%
- Scheme 29.9%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| docs | ||
| src/Model | ||
| templates/EmailTemplate | ||
| .gitignore | ||
| _config.php | ||
| composer.json | ||
| README.md | ||
silverstripe-templated-emails
A SilverStripe module that provides a unified, theme‑ready email template and automatically renders form data as a table—no manual HTML needed.
Installation
-
Install the package (in your project directory):
composer require moritz-sauer-13/silverstripe-templated-emails -
Update database/manifest:
- run /dev/build?flush=all
Requirements: SilverStripe CMS 5.x
Quick start
use SilverStripe\Control\Email\Email;
use TemplatedMails\Model\TemplatedEmail;
$email = TemplatedEmail::create()
->setTo('to@example.com')
->setFrom(Email::config()->admin_email)
->setSubject('Contact request')
->setGreeting('Hello,')
->setTitle('New contact request')
->setFormData($data, $form);
$email->send();
- If a
$formis provided, the order and labels are derived from the form fields. - Additional free text/HTML can still be set via
$email->setBody()and rendered in the template with$EmailContent.RAW.
Configuration (YAML)
Keys and defaults:
- skip_empty: true — Skip empty fields (default)
- excludes: ["SecurityID", "url", "g-recaptcha-response"] — Exclude exact key names
- exclude_prefixes: ["action_"] — Exclude all keys starting with any of these prefixes
- array_separator: ", " — Separator for array values
- label_from_placeholder: true — Use placeholder as label when Title is empty
- strip_required_asterisk: true — Remove trailing asterisk on required field labels
Example app/_config/email.yml:
TemplatedMails\Model\TemplatedEmail:
skip_empty: true
excludes:
- SecurityID
- url
- g-recaptcha-response
exclude_prefixes:
- 'action_'
array_separator: ', '
label_from_placeholder: true
strip_required_asterisk: true