Drupal - Send a Notification E-mail when a Comment is Posted
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
BWPanda (not verified)
Tue, 06/04/2013 - 02:07
Permalink
An even simpler solution is
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
Tue, 06/04/2013 - 09:02
Permalink
Thanks BWPanda. I will give
Thanks BWPanda. I will give that module a try soon!
Danny (not verified)
Wed, 06/05/2013 - 07:44
Permalink
The problem with Comment
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
Wed, 06/05/2013 - 16:52
Permalink
Interesting point Danny,
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
Wed, 06/05/2013 - 16:59
Permalink
I took the plunge and enabled
I took the plunge and enabled the Comment Notify module, I'll report back my thoughts on it if I remember ;)
Satyajit Deka (not verified)
Fri, 10/18/2013 - 06:01
Permalink
Hi...I did exactly what you
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
Fri, 10/18/2013 - 10:58
Permalink
I'd recommend flushing all of
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.
Drupal man (not verified)
Tue, 10/22/2013 - 15:57
Permalink
Yes, trigger solution is
Yes, trigger solution is better than rules.
Daniel Buccoliero (not verified)
Mon, 09/22/2014 - 07:39
Permalink
Hi Tyler
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
Mon, 09/22/2014 - 08:34
Permalink
Not that I'm aware of, I just
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...
Alex (not verified)
Thu, 12/04/2014 - 05:54
Permalink
Thanks tyler! But in my
tyler
Thu, 12/04/2014 - 10:10
Permalink
I'm not sure, if you're
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.