Using hook_mail_alter() for pending approval admin does not make any effect I want to disable the emails sent to admins when a new user account is being created, Account details for (user name) at site name. (pending admin approval).

I tried adding the piece of code in the hook_mail_alter function but that does not give me any change. Below is the code change that i made

function hook_mail_alter(&amp;$message) {
  if ($message['id'] == 'modulename_messagekey') {
    if ($message['id'] == 'modulename_register_pending_approval_admin') {
      $message['send'] = FALSE;
      return;
    }

    if (!example_notifications_optin($message['to'], $message['id'])) {
      // The usual code for sending mails.
    }
  }
}


Please let me know how can i disable the emails sent to admins.
I could not find any place where I can disable the email functionality from the UI end.
The emails are being sent because in admin/config/people/accounts the option Visitors, but administrator approval is required is selected for Who can register an account.


  


If you selected Visitors or Administrator only no email would be sent.

In the case you wanted to just avoid emails where sent to the administrators, but still wanted the administrator users to approve accounts, then the implementation of hook_mail_alter() should look for messages whose ID ($message['id']) is equal to user_register_pending_approval_admin_. Also, the example in the documentation of hooks don't show the correct name a hook implemented by a module should have: Always replace hook_ with the short name of the module implementing the hook.