Managing Site-owner Comment Notifications Using Triggers and Actions
Triggers and actions are a core feature of Drupal and have been for a really long time. But lots of people don't know that they can actually be useful for some very basic and important tasks. You might say this is a beginner topic, but since I've only mastered it for my own use in the last year or so, I figured it was worth writing about :-)
I use them mostly for notifications when comments have been posted to my blog, where comments are 100% moderated. (I use the wonderful Comment Notify to notify commenters when more comments are posted. If spam got posted they'd get email spam.)
So among the many things you can do simply with triggers and actions is configuring a notification to the site owner with details about the posted comment, and that's a great example of use of this simple feature. Here's how to do it.
First, create an action that does what you want.
In Drupal 7 it's easy to use tokens to customize the details of the outgoing email. At Administration -> Configuration -> System -> Actions (admin/config/system/actions) we can select "Send e-mail..." from the dropdown.
- Change the label to something like "Comment notification email"
- Set the recipient and subject (I use "Comment [comment:title] by [comment:author]" for the subject)
- The body can be something like this (adjusted to your needs)
Author: [comment:author]<br>Comment title: [comment:title]<br>Node title: [comment:node:title]<br>Comment URL: [comment:url:absolute]<br>All Comment Approvals: [site:url]admin/content/comment/approval<br>Body:<br>[comment:body]
Now set assign the action to a trigger
Oddly, the triggers configuration is in a completely different place in the menu hierarchy, and always has been. You can find it at admin/structure/trigger. We'll select the "Comment" category of triggers, and under "After saving a new comment" select the "Comment email" action we just created and save.
That's all there is to it. This is Drupal 7; the tokens are different than in earlier versions of Drupal, but the ideas are the same. If you want more power and the ability to apply conditions to your behavior, check out the excellent Rules module.
Update: D6 Recipe
For Drupal 6 the idea is the same. You need to enable the trigger and the token_actions module (which comes with the contrib Token module).
- Create an advanced action that is a "tokenized e-mail". The title can be something like "Comment: [comment-node-title]" and the mail can be your email.
Author: [comment-author-name]<br>Comment title: [comment-title]<br>Node title: [comment-node-title]<br>Comment Link: [node-url]#comment-[comment-cid]<br>All Comment Approvals: [site-url]admin/content/comment/approval<br>Body:<br>[comment-body]
- Go to admin/build/trigger/comment and assign the action you've created to "After saving a new comment".