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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Comment Moderation - Notifications?


Go to End


17 Posts   7466 Views

Avatar
Anatol

126 Posts

26 March 2010 at 2:17pm

Edited: 26/03/2010 2:17pm

Hi,

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.:

/mysite/_config.php

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

/mysite/code/PageCommentEmailNotification.php

<?php
class PageCommentEmailNotification extends DataObjectDecorator {
	function onAfterWrite() {
		 $email = new Email();
		 $email->setTemplate('NewComment');
		 $email->setTo('email@domain.com');
		 $email->setSubject('New Comment ' . str_replace(array("http://", "https://"), array("", ""), Director::absoluteBaseURL()));
		 $email->populateTemplate(Member::currentUser());
		 $email->populateTemplate(array(
			'URL' => Director::absoluteBaseURL() . $this->owner->Parent()->URLSegment,
			'PageTitle' => $this->owner->Parent()->Title,
			'Comment' => $this->owner->Comment,
		 ));
		 $email->send();
	}
}
?>

/themes/mytheme/email/NewComment.ss

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
   <head>
   </head>
   <body>
      <p>At $Created, $Name posted a new comment on the page <a href="$URL">$PageTitle</a>.</p>
      <p>Their comment:<br/>
      $Comment</p>
      <p>You can <a href="{$BaseHref}admin/comments/">administrate the comment</a>.</p>
   </body>
</html>

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.

Cheers!
Anatol

Avatar
Anatol

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 <email@domain.com>... 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.

[UPDATE]
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.

Cheers!
Anatol

Avatar
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?

Andy

Avatar
pinkp

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...

i.e. NewComment.ss

$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!

Avatar
DNA

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.

Avatar
UncleCheese

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. http://www.leftandmain.com

Avatar
borriej

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!

Thx!

Avatar
borriej

Community Member, 267 Posts

2 March 2011 at 4:36am

Up!