Send CMS editable system notifications from code

Installs: 243

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 12


1.0.2 2015-07-15 02:26 UTC

This package is auto-updated.

Last update: 2022-09-10 14:29:04 UTC


Send CMS managed system email notifications from code.

Maintainer Contacts


  • SilverStripe 3.1 +

Installation Instructions

composer require sheadawson/silverstripe-notifications

Creating System Notifications


In your _config yml file, add an identifier for each notification you require. This allows you to lookup Notification objects in the database from your code.



Add the NotifiedOn interface to any dataobjects that are relevant to the notifications you will be sending. This is required so the Notifications module can look up the below methods on your object to send the notification.

class MyDataObject extends DataObject implements NotifiedOn {

Define the following interface methods on the Object being notified on.

 * Return a list of available keywords in the format 
 * array('keyword' => 'A description') to help users format notification fields
 * @return array
public function getAvailableKeywords();
 * Gets an associative array of data that can be accessed in
 * notification fields and templates 
 * @return array
public function getNotificationTemplateData();

Note: the follow template data is automatically included:

  • $ThemeDir
  • $SiteConfig
  • $MyDataObject (whatever the ClassName of your NotifiedOn DataObject is)
  • $Member (The Member object this message is being sent to)
 * Gets the list of recipients for a given notification event, based on this object's 
 * state. 
 * $event The identifier of the event that triggered this notification
 * @return array An array of Member objects	
public function getRecipients($event);

Note: getRecipients() can return an array of any objects, as long as they have an Email property or method


Create a notification in the Notifications model admin, in the CMS.


Send the notification from your code, where $contextObject is an instance of the DataObject being NotifiedOn

singleton('NotificationService')->notify('NOTIFICATION_IDENTIFIER', $contextObject);


Notifications can be rendered with .ss templates. This is useful if you want to have a header/footer in your email notifications. You can either specify a template on a per/notification basis in the CMS, and/or set a default template for all notifications to be rendered with:

  default_template: EmailNotification

In your templates, you render the notification text with the $Body variable.


You will probably want to configure a send_from email address -

  send_notifications_from: ''


  • Test with QueuedJobs module for handling large amounts of notifications in configurable batches/queues