SilverStripe Page Comment Email Notification

Receive an email when a new page comment has been posted. Works with SilverStripe 2.3+ including version 2.4.


Either download the source code from the file or copy and paste the code from below.


Add the following two lines to your /mysite/_config.php file to enable email notifications. Remember to change the email to your address!

DataObject::add_extension('PageComment', 'PageCommentEmailNotification');

Source code

Download source PageCommentEmailNotification.zipor copy and paste the code from below into files you create:

File: mysite/code/PageCommentEmailNotification.php


class PageCommentEmailNotification extends DataObjectDecorator {
  function onAfterWrite() {
      if ($this->NeedsModeration) {
            $email = new Email();
            $email->addCustomHeader('Reply-To', Member::currentUser()->Email);
            $email->setSubject('New Comment ' . str_replace(array("http://", "https://"), array("", ""), Director::absoluteBaseURL()));
                'URL' => Director::absoluteBaseURL() . $this->owner->Parent()->URLSegment,
                'PageTitle' => $this->owner->Parent()->Title,
                'Comment' => $this->owner->Comment,

File: themes/yourtheme/templates/email/

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
                font-size: 1.2em;
                color: #444;
                font-size: 1.4em;
                color: #222;
                padding: 20px;

        <p><% if CurrentMember.Email %><a href="mailto:$CurrentMember.Email">$CurrentMember.Name</a><% else %>$CurrentMember.Name<% end_if %>,  posted a new comment on the page <a href="{$URL}">$PageTitle</a>.</p>

        <p>Their comment:<br/>
        <p>You can <a href="{$BaseHref}admin/comments/">administrate the comment</a>. You can reply to the sender direct by email.</p>