1

whenever user creates content, I want to get the few fields data of content in the mail body and trigger mail,, as of now i have created rule to trigger mail with text comparison condition for specific field.

ex: I have content with user id, pancard Id fields etc,now i want to get this content field data in mail body and send mail to user.

7
  • 1
    Have you install token or entity token module? If it is eable you can add token of that field on message of that rules.
    – vgoradiya
    Sep 16, 2015 at 6:42
  • @VimalGoradiya: yes i have enabled
    – kashish
    Sep 16, 2015 at 6:51
  • 1
    then use the tokens in ur mail body field...
    – No Sssweat
    Sep 16, 2015 at 6:59
  • @ No Sssweat: do we need to add fields tokens in the body, along with text????
    – kashish
    Sep 16, 2015 at 7:10
  • 1
    @kashish It should be something like [comment:comment-body] along with your text thats it.
    – vgoradiya
    Sep 16, 2015 at 7:22

2 Answers 2

1

Depending on the kind of rule event which I expect to be "When a new content is created" in your case.

When you choose action of rule as "send email" it allows you to use tokens, as declared by token modules. You will see the node tokens for the field as well, use it and those will get automatically replaced.

0
0

you can use the hook_node_insert.

function yourmodule_node_insert(&$node) {
  $body = $node->body;
  drupal_mail('yourmodule', 'your_key', $to, user_preferred_language($user), array('body' => $body), $from, TRUE);
}

This hook will trigger whenever you create a node.

and then use hook_mail

function yourmodule_mail($key, &$message, $params) {
  switch ($key) {
    case 'your_key':
      $message['body'][] = t('@body', array('@body' => $params['body']));
      $message['subject'] = $subject;
      break;

  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.