2

I'm currently importing a whole bunch of users to a site programmically through user_save. How can I make sure that no registration mails are sent to the users?

// Create new user
$newUser = array(
    'name' => $member->name,
    'pass' => $member->password,
    'mail' => $email,
    'field_user_fullname' => array('und' => array(array('value' => $member->navn))),
    'status' => 1,
    );
user_save(null, $newUser);
3

I can't find a way to do that. user_save doesn't take such an argument. I believe you have two options.

  1. Emulate the user_register_submit() call by passing your data in as a form instead, this is preferably done with drupal_form_submit(). It just so happens that the example deals with user-registration.
  2. Just kill outgoing e-mails while you import your users.
  • +1 drupal_form_submit() would probably be the best way to go – Clive Feb 20 '12 at 11:12
3

The simple answer is you can't I'm afraid, it's hard-coded into the user_save() function with this bit of code:

// Send emails after we have the new user object.
if ($account->status != $account->original->status) {
  // The user's status is changing; conditionally send notification email.
  $op = $account->status == 1 ? 'status_activated' : 'status_blocked';
  _user_mail_notify($op, $account);
}

That checks the original account object (which is loaded up there and then so it can't be altered) against the new account object and if there's a difference in the status it sends an email.

The only way I can think to do it would be to simulate a submission of the user_register_form which has a checkbox denoting whether or not to notify the user of changes.

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.