3

I'm trying to implement an access check (a 'do-not-send' list query) just before emails are sent. I see how to modify the message, but how do I stop a message?.

HOOK_mail ($key, &$message, $params) {
   if (TRUE) {
      // -- Stop Message From Being Sent Here -- //
   }
}

Is break; adequate?

1 Answer 1

8

You can do the access check from hook_mail_alter instead of hook_mail (let it prepare the default message based on parameters, and alter it later) by something like:

function HOOK_mail_alter(&$message) {
  // can add additional check for particular mails here,
  // by checking the value in $message['id']
  if (TRUE) {
    $message['send'] = FALSE;
  }
}

Note: You should clear the cache in order to make the changes effective.

1
  • 3
    In case someone is wondering, this still works for Drupal 8.
    – Gnuget
    Commented Jan 12, 2017 at 21:32

Your Answer

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

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