When a user wants to create a new account and is sent an approval needed email. The first admin account gets sent the register_pending_approval_admin email. Although I do not want user 1 to get these emails because I don't want that user to have to deal with dealing with account approval. Instead I want to send this email to another user or a created role that deals with account approval. I am unsure of how to do this. Could someone please help me on stopping this email in going to user 1 and instead going to a different user (with user administration privileges) or to users within a role (with user administration privileges).

Any help would be much apprectiated,
Tom Heard

Comments

tcheard’s picture

This is what I have tried, although I'm now getting a
Error sending e-mail from **********@**************** to : You must provide at least one recipient email address.
Error. Meaning that no emails are being sent even though I should have one email as output.

This is what I did. I altered the _user_mail_notify function modules/user/user.module from:

function _user_mail_notify($op, $account, $language = NULL) {
  // By default, we always notify except for deleted and blocked.
  $default_notify = ($op != 'status_deleted' && $op != 'status_blocked');
  $notify = variable_get('user_mail_'. $op .'_notify', $default_notify);
  if ($notify) {
    $params['account'] = $account;
    $language = $language ? $language : user_preferred_language($account);
    $mail = drupal_mail('user', $op, $account->mail, $language, $params);
    if ($op == 'register_pending_approval') {
      // If a user registered requiring admin approval, notify the admin, too.
      // We use the site default language for this.
      drupal_mail('user', 'register_pending_approval_admin', variable_get('site_mail', ini_get('sendmail_from')), language_default(), $params);
    }
  }
  return empty($mail) ? NULL : $mail['result'];
}

to:

function _user_mail_notify($op, $account, $language = NULL) {
  // By default, we always notify except for deleted and blocked.
  $default_notify = ($op != 'status_deleted' && $op != 'status_blocked');
  $notify = variable_get('user_mail_'. $op .'_notify', $default_notify);
  if ($notify) {
    $params['account'] = $account;
    $language = $language ? $language : user_preferred_language($account);
    $mail = drupal_mail('user', $op, $account->mail, $language, $params);
    if ($op == 'register_pending_approval') {
      // If a user registered requiring admin approval, notify the admin, too.
      // We use the site default language for this.
      $rid = 5;
      $result = db_query("SELECT u.uid, u.mail FROM {users} u
      INNER JOIN {users_roles} ur ON u.uid=ur.uid WHERE ur.rid = %d
      AND u.status = 1", $rid);
      $u = db_fetch_object($result);
      foreach($u as $approver){
         drupal_mail('user', 'register_pending_approval_admin', variable_get($approver->mail, ini_get('sendmail_from')), language_default(), $params);
      }
    }
  }
  return empty($mail) ? NULL : $mail['result'];
}

Can anybody tell me what I have done wrong?

tcheard’s picture

I see that I can't use variable_get($approver->mail, ini_get('sendmail_from')) on a variable that I created, now. But what should I do instead. Would $approver->mail be in something other than a string?
eg can I do,

drupal_mail('user', 'register_pending_approval_admin', $approver->mail, language_default(), $params);

?
I just need some guidance.

Tom Heard

tcheard’s picture

This is what I have so far:

function _user_mail_notify($op, $account, $language = NULL) {
  // By default, we always notify except for deleted and blocked.
  $default_notify = ($op != 'status_deleted' && $op != 'status_blocked');
  $notify = variable_get('user_mail_'. $op .'_notify', $default_notify);
  if ($notify) {
    $params['account'] = $account;
    $language = $language ? $language : user_preferred_language($account);
    $mail = drupal_mail('user', $op, $account->mail, $language, $params);
    //This next part works for one approver, after that it doesn't send more emails. Needs to be fixed!
    if ($op == 'register_pending_approval') {
      // If a user registered requiring admin approval, notify the user approval admin, too.
      // We use the site default language for this.
      $rid = 5;
      $result = db_query("SELECT u.mail FROM users u, users_roles ur WHERE ur.rid = %d AND u.status = 1 AND u.uid = ur.uid", $rid);
      $u = db_fetch_object($result);
      drupal_mail('user', 'register_pending_approval_admin', $u->mail, language_default(), $params);
    }
  }
  return empty($mail) ? NULL : $mail['result'];
}

This works with one approval admin, but if I have more then one, it just sends it to the first one. How do I go about sending it to all of them.

Thanks,
Tom