Jump to:

10851 Posts in 2517 Topics by 1793 members

All other Modules

SilverStripe Forums » All other Modules » Comment Moderation - Notifications?

Discuss all other Modules here.

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

Page: 1 2 3
Go to End
Author Topic: 4428 Views
  • Anatol
    Avatar
    126 Posts

    Re: Comment Moderation - Notifications? Link to this post

    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

  • Anatol
    Avatar
    126 Posts

    Re: Comment Moderation - Notifications? Link to this post

    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

  • Andrew Houle
    Avatar
    Community Member
    132 Posts

    Re: Comment Moderation - Notifications? Link to this post

    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

  • pinkp
    Avatar
    Community Member
    168 Posts

    Re: Comment Moderation - Notifications? Link to this post

    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!

  • DNA
    Avatar
    Community Member
    24 Posts

    Re: Comment Moderation - Notifications? Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Comment Moderation - Notifications? Link to this post

    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

  • borriej
    Avatar
    Community Member
    267 Posts

    Re: Comment Moderation - Notifications? Link to this post

    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!

  • borriej
    Avatar
    Community Member
    267 Posts

    Re: Comment Moderation - Notifications? Link to this post

    Up!

    4428 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.