function user_register_notify_setup_email in User registration notification 7
Same name and namespace in other branches
- 6 user_register_notify.module \user_register_notify_setup_email()
Send e-mail notification.
4 calls to user_register_notify_setup_email()
- user_register_notify_profile2_update in ./
user_register_notify.module - Implements hook_profile2_update().
- user_register_notify_user_delete in ./
user_register_notify.module - Implements hook_user_delete().
- user_register_notify_user_insert in ./
user_register_notify.module - Implements hook_user_insert().
- user_register_notify_user_update in ./
user_register_notify.module - Implements hook_user_update().
File
- ./
user_register_notify.module, line 89 - Installation file for the user_register_notify module.
Code
function user_register_notify_setup_email(&$account, $action = 'create') {
// Notify administrator of new user only if this is not first user.
if ($account->uid != 1) {
$notify_type = variable_get('user_register_notify_type', 'custom');
$params = array(
'account' => $account,
);
// Default 'from' e-mail address to drupal_mail().
$from = variable_get('site_mail', ini_get('sendmail_from'));
$emails = array();
switch ($notify_type) {
case 'custom':
$user_register_notify_mail_to = variable_get('user_register_notify_mail_to', $from);
if (!empty($from)) {
$emails = explode(',', $user_register_notify_mail_to ? $user_register_notify_mail_to : $from);
}
break;
case 'both':
$user_register_notify_mail_to = variable_get('user_register_notify_mail_to', $from);
if (!empty($from)) {
$emails = explode(',', $user_register_notify_mail_to ? $user_register_notify_mail_to : $from);
}
// There is no 'break' here to include the role e-mails below.
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 (:roles) and u.status = :status", array(
':roles' => $roles,
':status' => 1,
));
while ($mail = $result
->fetchObject()) {
$emails[] = $mail->mail;
}
}
break;
}
// Make sure the e-mail addresses from users table are clean.
$emails = array_map('trim', $emails);
$emails = array_filter($emails, 'strlen');
$emails = array_unique($emails);
if (empty($emails)) {
watchdog('user_register_notify', 'Cannot send user notification without recipient e-mail address.', WATCHDOG_WARNING);
return;
}
$to = implode(', ', $emails);
// watchdog('user_register_notify', check_plain($to));
drupal_mail('user_register_notify', 'admin_' . $action, $to, language_default(), $params, $from, TRUE);
}
}