You are here

function user_register_notify_setup_email in User registration notification 6

Same name and namespace in other branches
  1. 7 user_register_notify.module \user_register_notify_setup_email()
1 call to user_register_notify_setup_email()
user_register_notify_user in ./user_register_notify.module
Implementation of hook_user().

File

./user_register_notify.module, line 43
Notifies administrator of new user registrations.

Code

function user_register_notify_setup_email(&$edit, &$account, $action = 'insert') {

  // Notify administrator of new user only if this is not first user and
  // if visitors can create accounts without administrator's approval.
  // In case when accounts must be created with administrator's approval
  // there is already a 'pending approval' e-mail notification.
  if ($account->uid != 1 && (variable_get('user_register', 1) == 1 ? $account->status : !$account->status)) {
    $notify_type = variable_get('user_register_notify_type', 'Custom');
    $from = variable_get('site_mail', ini_get('sendmail_from'));
    $params = array(
      'account' => $account,
      'action' => $action,
    );
    $emails = array();
    switch ($notify_type) {
      case 'Custom':
        $emails = preg_split('/,[\\w]+/', variable_get('user_register_notify_mailto', $from));
        break;
      case 'Both':
        $emails = preg_split('/,[\\w]+/', variable_get('user_register_notify_mailto', $from));

      // There is no break here for a reason.
      case 'Role':
        $roles = variable_get('user_register_notify_roles', array());
        if (!empty($roles)) {
          $result = db_query("SELECT mail FROM {users} AS u INNER JOIN {users_roles} AS r ON u.uid = r.uid WHERE r.rid IN(" . db_placeholders($roles, 'int') . ") and u.status = '1'", $roles);
          while ($mail = db_fetch_object($result)) {
            $emails[] = $mail->mail;
          }
        }
        break;
    }
    $emails = array_unique($emails);
    $to = implode(', ', $emails);

    //    watchdog('user_register_notify', check_plain($to));
    drupal_mail('user_register_notify', 'user-register-notify-admin', $to, language_default(), $params, $from, TRUE);
  }
}