Error message

Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /home1/tylerfra/public_html/includes/common.inc).

Drupal - Send a Notification E-mail when a Comment is Posted

Category: 

To receive an e-mail notification when a new comment is posted, try this (you won't even need to write one line of code):

1. Enable the 'Trigger' Module

Go to admin/modules and enable the Trigger module if it isn't already.

2. Create an Advanced Action

Go to admin/config/system/actions and scroll down to the 'Create an Advanced Action' section. Select 'Send e-mail' from the drop down menu, then press the 'Create' button.

3. Setup the Advanced Action

  • Enter a Label for your action, for example "Send an E-mail to Myself when Comments are Posted".
  • Enter the recipient e-mail address
  • Enter the Subject of the e-mail notification
  • Enter the Message for the body of the e-mail

This particular 'Message' will work well:

[site:url]/admin/content/comment/approval
[site:url]/comment/[comment:cid]/delete

[comment:node:title]
[comment:node:url]

From: [comment:name]

[comment:body]

It contains quick links to approve or delete the comment, it also sends along the node title, a link to the node, the name of the comment poster, and the comment message. If you do not have comments set to require administrative approval, you can leave out the link to admin/content/comment/approval. Use the table of tokens below the message text area for data placeholders in the e-mail to meet your needs.

4. Add the Action to a Trigger

Go to admin/structure/trigger/comment then to the "Trigger: After Saving a New Comment" section, then select the your action from the 'Choose an action' drop down menu, then click the 'Assign' button.

5. Conclusion

That's it! You now have e-mail notifications for new comments posted on your Drupal site.

Do you have any tricks for comment notifications in Drupal? Please share your thoughts.

Comments

An even simpler solution is to just install the Comment Notify module.
Not only can you configure it to email you whenever new comments are posted to your nodes, but anonymous users can receive notifications for replies to their comments!

tyler's picture

Thanks BWPanda. I will give that module a try soon!

The problem with Comment Notify I found was that you don't receive any emails until you approve the comment. So for admin purposes it totally defeats the purpose of using the module. It is good for anonymous users though...

tyler's picture

Interesting point Danny, thanks for pointing it out. The reason I used the approach described above was exactly for an admin's perspective (I receive more spam comments than legitimate comments, using mollom). Like you said, it Comment Notify sounds nice as a way to keep site visitor commentors up to date with notifications.

tyler's picture

I took the plunge and enabled the Comment Notify module, I'll report back my thoughts on it if I remember ;)

Hi...I did exactly what you said. But the emails are not send when a new comment is saved. I have no idea. Please provide some solution on this.....

tyler's picture

I'd recommend flushing all of Drupal's caches. Then if that doesn't work, I would start over and make sure every step was followed exactly. If that doesn't work, confirm that your server is properly configured to send out e-mails. A quick test would be to fill out your contact form and make sure the message gets delivered.

Yes, trigger solution is better than rules.

Hi Tyler

Similarly to the topic above, is there an easy way to similarly send a notification email when a file is upoaded?

Kind regards

tyler's picture

Not that I'm aware of, I just took a quick look on my site and I don't have any triggers for Files. Perhaps the Rules module could handle this?

There appear to be many topics on this subject though: https://www.google.com/search?client=ubuntu&channel=fs&q=drupal+file+tri...

Thanks tyler! But in my Drupal 7,  [comment:cid] have not value. Do you know why?

 

 

tyler's picture

I'm not sure, if you're setting up a comment action, the cid token should definitely be available. Use the "browse available tokens" link to see what is available.