1

I'm using the Drupal 7 Rules module to trigger and send emails on specific events, but need to modify the email headers before the message is sent.

What would be the appropriate way to add 'reply-to' headers (as used in RFC 5322) to specific outgoing emails that are sent using the Drupal 7 Rules module?

The following works when using drupal_mail() but I do not see how to apply this hook when using Rules.

function hook_mail($key, &$message, $params) {
    switch ($key) {
        case 'key_name_here':
            $message['Reply-to'] = $params['mail'];
            $message['subject'] = $params['subject'];
            $message['body'] = $params['body'];
            $message['headers']['Reply-To'] = $params['mail'];
            break;    
    }
}
// One note to the above script, lines 4 and 7 seem redundant and likely need work.
2

You can still use hook_mail, you just need to identify the key for the rule or rules you want to override. The key is set in the rules_action_mail() function $key = 'rules_action_mail_' . $name . '_' . $element->elementId(); where name is the rule name and element id is the numeric id for the rule. You need to make sure your custom module has a higher weight that the rules module in the system table of your database.

  • This worked perfectly. I should have over rules_action_mail() before posting, but wouldn't have found it without your suggestion. Thank you. – Citricguy Apr 10 '12 at 3:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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