moritz-sauer-13/silverstripe-templated-emails

There is no license information available for the latest version (1.0.1) of this package.

Adds an easy way to create email templates in SilverStripe

Installs: 8

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/moritz-sauer-13/silverstripe-templated-emails

1.0.1 2025-10-01 15:08 UTC

This package is auto-updated.

Last update: 2025-10-01 15:08:46 UTC


README

A SilverStripe module that provides a unified, theme‑ready email template and automatically renders form data as a table—no manual HTML needed.

Preview of the default email template

Installation

  1. Install the package (in your project directory):

    composer require moritz-sauer-13/silverstripe-templated-emails
  2. 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 $form is 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