开发者

How to send an email when a user responds to a comment

开发者 https://www.devze.com 2023-02-23 06:42 出处:网络
What I want is to announce the original comment poster, when someone has responded on his comment It\'s a bit blurry on how to do this with trigge开发者_JAVA百科rs.

What I want is to announce the original comment poster, when someone has responded on his comment It's a bit blurry on how to do this with trigge开发者_JAVA百科rs.

Has anybody done that, or is there another way to do this?


I'm not sure exactly how to do it with the core Triggers module, but this can definitely be done with the Rules Module (assuming Drupal 6... not sure of any issues with Drupal 7 version of Rules).

  1. Download and install Rules

  2. Navigate to admin/rules/trigger/add to create a new rule, name it whatever you like and under the Event dropdown, choose "After saving a new comment" and click Save

  3. Click on the "Add a condition" link choose "Execute custom PHP code". In the PHP code area, add the following then click save:

    if ($comment->pid != 0) { return TRUE; } else { return FALSE; }

  4. Click "Add an action" and choose "Load comment by id". In the Comment id field add: <?php echo $comment->pid; ?> and click Save

  5. Click "Add an action" again and choose "Load a user account". In the User id field add: <?php echo $comment_loaded->uid; ?> and click Save

  6. Click "Add an action" again and choose "Send a mail to an arbitrary mail address". In the Recipient field add: <?php echo $user_loaded->mail; ?> and fill in the other fields however you like to customize the email.

Now whenever a comment is replied to, an email will be sent to the "replied-to" comment author.


For Drupal 7 website
Here is the code you can import under rules and update your subject and body as per your requirement:

{ "rules_send_reply_notice_for_comments" : {
"LABEL" : "Send reply notice for comments",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"TAGS" : [ "comments" ],
"REQUIRES" : [ "rules", "comment" ],
"ON" : { "comment_insert" : [] },
"IF" : [ { "NOT data_is_empty" : { "data" : [ "comment:parent" ] } } ],
"DO" : [
  { "mail" : {
      "to" : [ "comment:parent:mail" ],
      "subject" : "SUBJECT",
      "message" : "Here is the message you want to send [comment:body] regards Gaurav",
      "from" : "YOUR EMAIL ADDRESS",
      "language" : [ "" ]
    }
  }
]  } }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号