1

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(&$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.

1
  • Welcome to Drupal Answers! Are you showing the code you are really using? If it is so, then that is totally wrong, starting from the function name. – kiamlaluno Nov 4 '15 at 21:06
0

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.

screenshot

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.

2
  • hi, Thank u for the reply .I am new to drupal,so I am not sure of the module that implements the hook.I tried replacing the function name that implements the hook with the drupal_mail and system_mail modules and changed the $message['id '] as u mentioned.I made these changes in the system.api.php file. Please let me know am I making the changes in the correct file.any suggestion are appreciated. thanks in advance.Mentioned the sample code in below comment @kiamlaluno – MaArc Nov 5 '15 at 19:19
  • function drupal_mail_alter(&$message) { // Stop the default drupal email that goes out to admins when a user // registers on the site. An alternative email is sent out via other means. if ($message['id'] == 'user_register_pending_approval_admin_') { $message['send'] = FALSE; } } – MaArc Nov 5 '15 at 19:22

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.