This might be a silly question but I can't seem to find the solution.
How can I disable the automatic email notification of the new user account that user sends to users after they register?

Thanks!

Comments

drozzy’s picture

TYPO*
user sends to users after they register? -> drupal sends to users after they register?

vm’s picture

goto administer -> user settings

uncheck Require e-mail verification when a visitor creates an account

drozzy’s picture

I should mention I am in Drupal 5

Magnity’s picture

You can disable some emails such as account activation from /admin/user/settings, but I believe if you wish to disable the registration email you'll have to edit the code.

(So not sure that this is the help you wanted...)

Magnity

http://webdesign.magnity.co.uk

drozzy’s picture

I can't disable that from admin. What I am interested in disabling is the "welcome email", but in user settings it only shows the email message I can customize. I can't turn it off :-(

I am trying to find where in code can I disable it. I've look at the user module - but I can't seem to find the spot :-(((

Any help?

drozzy’s picture

* bump* can at least someone tell me which module to look in?

vm’s picture

probably the user.module though I don't advocate hacking core modules.

drozzy’s picture

ha, everyone says they don't advocate hacking core modules , but no-one gives alternative solutions.
It's like if someone asks me "Hey man, is there a place I can eat around here, I am really starving..."
i would answer:
"There is a burger king around the corner - but I don't advocate eating there" ???

walker2238’s picture

Hey drozzy not sure if you've figured this out yet but the direct answer to your question is just hack the user.module file I had to do the same thing but my reason is because my host (hostican) has a 100 e-mail limit per month... crazy stuff... don't get me started...
anyways look for the function called user_register_submit. You'll scroll just below is and you'll find this...

    else if (!variable_get('user_email_verification', TRUE) && $account->status && !$admin) {
      // No e-mail verification is required, create new user account, and login user immediately.
      $subject = _user_mail_text('welcome_subject', $variables);
      $body = _user_mail_text('welcome_body', $variables);
      drupal_mail('user-register-welcome', $mail, $subject, $body, $from);
      user_authenticate($account->name, trim($pass));
      $edit = array();
      user_module_invoke('login', $edit, $account);
      return '';
    }

comment out or remove this line and no e-mail will be sent.

      drupal_mail('user-register-welcome', $mail, $subject, $body, $from);
1kenthomas’s picture

Don't hack core; mod it and replace in sites/example.com/modules or via another method ;), leaving core intact; keep a patches directory or other documentation so things are clear if and when core gets updated.

buddhika’s picture

hook_mail_alter (http://api.drupal.org/api/function/hook_mail_alter/5) can be used to change mails sent using drupal_mail() function (such as the welcome mail). You can recognize the mail by mail ID given (for example welcome mail ID is user-register-welcome). So using something like this you can modify the mail.

function your_module_mail_alter(&$mailkey, &$to, &$subject, &$body, &$from, &$headers){

     if ($mailkey == 'user-register-welcome'){
          //do what ever you want
     }

}

I don't know a 'proper' method to disable the welcome mail (that's without counting hacking user module). But through some gimmicks we can make it look like disabling the welcome mail. Just change the $to address to some unused mail box within your mail_alter and it's as good as disabling the mail for me ;)

Buddhika
http://luckycala.wordpress.com

Web Assistant’s picture

Just want to say thanks to buddhika for some good advice. I spend hours and hours trying to disable the stupid welcome email without hacking core modules. The idea of just changing the 'to' address is actually pretty perfect as I can just send it to a private inbox, this inbox can be used as a backup of user information.

balsama’s picture

I like this solution, but can't seem to get the syntax correct to work in Drupal 6. Does anyone have a working example of the code for Drupal 6?

Thanks.

robin van emden’s picture

Try: http://drupal.org/project/advanced_mail_reroute .
It discovers mailkeys (specific places where mail is send), after which you can selectively enable, disable or reroute e-mail.

bart atlas’s picture

The key is in _user_mail_notify function of user.module

Each email that is sent has an associated variable, which determines whether or not notification should happen for each operation.

These are in the format 'user_mail_ZZZ_notify', where ZZZ is the operation.

So, if under Administer -> User Management -> User Settings, you have selected the option "Visitors can create accounts and no administrator approval is required."

...then to prevent the emails from being sent you would set in the code for your module:

variable_set('user_mail_register_no_approval_required_notify', false);

pvhee’s picture

Thanks for this insight, it indeeds disables the sending of email. However, it seems to be incomplete, as a message like 'Your password and further instructions have been sent to your e-mail address.' would still appear.

Taking a look at the code, I found the following asymmetry, at line 2359 of user.module

$op = $notify ? 'register_admin_created' : 'register_no_approval_required';
      _user_mail_notify($op, $account);
      if ($notify) {
        drupal_set_message(t('Password and further instructions have been e-mailed to the new user <a href="@url">%name</a>.', array('@url' => url("user/$account->uid"), '%name' => $account->name)));
      }

Thus, even if _user_mail_notify does *not* send the email (with the hint above), drupal will emit a message that an email has been sent. So a complete solution does not seem possible without hacking user.module...

bart atlas’s picture

You can use a Trigger or hook form_alter to redirect the user after registration to your custom page, to the user login page, etc. Easy and safer than core hacking.

function yourmodule_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'user_register') {
$form['#redirect'] = 'home';
}
}

You could also choose to automatically log the user in after registration, which is what my site does and why I failed to notice this bit you pointed out. The site I'm developing for is using Email Registration with latest the patch that automatically logs the user in after registration, thereby showing a different page to the user... so my users don't see a registration message either on screen or by email.

The example below does an auto-login for ordinary users at registration, was pinched from Email Registration module's patch and tweaked:

function yourmodule_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {

case 'insert':
global $user;

// if email verification is off and a new user is the one creating account, log the new user in with correct name
if (!variable_get('user_email_verification', 1) && $user->uid == 0) {
$user = $account;
}
break;
}

}

soyarma’s picture

A nice way to do this with no code hacks would be to use the advanced mail reroute to nuke the emails you want to get rid of, and then the string overrides module to alter the messages.

mdost@sharpdotinc.com’s picture

In Drupal 6 you can set a variable that will contole the email.

Add this variable to your site and set it to false to disable sending welcome emails.

variable: user_mail_register_no_approval_required_notify

//Example function called to show the settings page for this var
function MODULE_admin(){
  $form = array();
	
  $form['user_mail_register_no_approval_required_notify'] = array(
    '#type' => 'radios',
    '#title' => t('Send Welcome Email'),
    '#default_value' => variable_get('user_mail_register_no_approval_required_notify', true),
    '#options' => array(t('False'), t('True')),    
  );

  return system_settings_form($form);
}
opi’s picture

Thanks for poiting me (us) this variable, I was hardly looking for a way do disable these email.

Could we put that radio/checkbox into the user_admin_settings form directly ?, by doing

function MYMODULE_form_user_admin_settings_alter(&$form, &$form_state) {
  // allow admin to choose if a notification mail is sent to user (who register without approval)
  $form['email']['no_approval_required']['user_mail_register_no_approval_required_notify'] = array(
    '#type' => 'checkbox',
    '#title' => t('Send'),
    '#default_value' => variable_get('user_mail_register_no_approval_required_notify', true),
  );
}
scottatdrake’s picture

This worked perfectly for me.

dunklea’s picture

This worked for me as well. Thanks!

wOOge’s picture

Slight modification for D7:

function YOURMODULENAME_custom_form_user_admin_settings_alter(&$form, &$form_state) {
	// allow admin to choose if a notification mail is sent to user (who register without approval)
	$form['email_no_approval_required']['user_mail_register_no_approval_required_notify'] = array(
		'#type' => 'checkbox',
		'#title' => t('Send'),
		'#default_value' => variable_get('user_mail_register_no_approval_required_notify', true),
	);
}

Some other variables you can use:

'user_mail_register_admin_created_notify': Welcome message for user created by the admin.
'user_mail_register_no_approval_required_notify': Welcome message when user self-registers.
'user_mail_register_pending_approval_notify': Welcome message, user pending admin approval.
'user_mail_password_reset_notify': Password recovery request.
'user_mail_status_activated_notify': Account activated.
'user_mail_status_blocked_notify': Account blocked.
'user_mail_cancel_confirm_notify': Account cancellation request.
'user_mail_status_canceled_notify': Account canceled.

--
wOOge | adrianjean.ca

reszli’s picture

if someone is still looking for a solution for this issue
you can check the following module:

http://drupal.org/project/mailcontrol

it provides the necessary UI additions for D7 (and D8) to enable site admins to enable/disable any standard Drupal mail
a version for D6 is under development and will soon be available

Drupal Developer @Dropsolid

skessler’s picture

Mailcontrol worked like a charm.
If you are looking for the configuration it is right with the Drupal user configuration. Great module!

Steve Kessler

deveshkumar’s picture

function <MODULENAME>_mail_alter(&$message)
{
    if ($message['id'] == 'user_register_no_approval_required') {
        $message['send'] = false;
    }
}