Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Comment Moderation - Notifications?

Go to End

17 Posts   6551 Views


126 Posts

26 March 2010 at 2:17pm

Edited: 26/03/2010 2:17pm


thanks for all of this so far. This is a really useful thread. It just won't work for me just yet. I pretty much copied everything from Marijn into my Silverstripe project, i.e.:


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


class PageCommentEmailNotification extends DataObjectDecorator {
	function onAfterWrite() {
		 $email = new 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,


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
      <p>At $Created, $Name 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>.</p>

No error message, but I never receive any email.
I ran dev/build?flush=all (in case that's necessary).
I also tried Object::add_extension instead of DataObject::add_extension ...
The project is on Silverstripe 2.3.5

What am I missing? Any hint is highly appreciated.



126 Posts

26 March 2010 at 3:54pm

Edited: 26/03/2010 5:12pm

Hi again,

OK, it actually seems to work but I discovered a problem with the mail delivery itself. The emails are on my VPS in /var/spool/mail/root and it says "Action: failed", "Diagnostic-Code: SMTP; 550 5.1.1 <>... User unknown" (but actually it's not unknown). Also it's weird that my maillog files are empty.

So it's a different problem all together and not related to Silverstripe at all. I guess I will go looking for this solution elsewhere.

More or less solved. It didn't work when I used an email address with a domain name that's hosted on the same VPS server that the Silverstripe project is installed at. For some reason in this case sendmail tries to deliver the email directly to the same server and can't find the user ('user unknown'). This is because I use Google Apps and the email should really leave the server (but sendmail only tries an 'internal mail' delivery). I could solve it for now simply by using an external email address in $email->setTo. To completely fix the issue I probably need to change some sendmail configurations...

Again, thanks for this very useful thread.


Andrew Houle

Community Member, 140 Posts

14 April 2010 at 1:45am

This comment moderation script works perfectly. My issue is this, I have many news pages on my site. I'm trying to revise this to only send an email to the publishers who have access (in the CMS) to that portion of the site. Any ideas, how I can target those members, based on which comment form is submitted?



Community Member, 182 Posts

14 June 2010 at 2:35am

This works great for registered users but how do I populate the email with just the name entered in the Name filed of the comment form for people not logged in...


$Created, $Name

Are returning blank in my email when not logged in but give the time and user name when logged in... do i need to change the PageCommentEmailNotification.php? mine is the same as the ones previously posted. Thanks!


Community Member, 24 Posts

30 September 2010 at 12:17pm

You could create a has_one link to a person object for the page object, then during your email routine look at the page and it's associated person object for the email address you want to send to.


Forum Moderator, 4102 Posts

3 February 2011 at 5:11am

Works great! Only problem was the grammar error in the email. "Their comment" needs to be "His or her comment"..

Hahaha... oh, man. Good thing you guys like me.

Silverstripe tips, tutorials, screencasts, and more.


Community Member, 267 Posts

20 February 2011 at 2:16am

Edited: 20/02/2011 2:18am

Doesn't work great for me :(

When im NOT logged... and try to post a fresh comment:.
I get a popup error!

The popup displays the HTML code with in the $Content:
- Sorry there was a problem handling your request..

How can i also let this script work for users not logged in?

When im logged in, it does work perfectly!



Community Member, 267 Posts

2 March 2011 at 4:36am