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.

All other Modules

Discuss all other Modules here.

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

Comment Moderation - Notifications?


Reply

17 Posts   4705 Views

Avatar
Anatol

26 March 2010 at 2:17pm (Last edited: 26 March 2010 2:17pm), 126 Posts

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

26 March 2010 at 3:54pm (Last edited: 26 March 2010 5:12pm), 126 Posts

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

14 April 2010 at 1:45am Community Member, 132 Posts

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

14 June 2010 at 2:35am Community Member, 168 Posts

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

30 September 2010 at 12:17pm Community Member, 24 Posts

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

3 February 2011 at 5:11am 4085 Posts

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

20 February 2011 at 2:16am (Last edited: 20 February 2011 2:18am), Community Member, 267 Posts

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

2 March 2011 at 4:36am Community Member, 267 Posts

Up!