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?


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.

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

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.