Conditionally create and send a notification email when a certain operation happens on the given user account.
$op: The operation being performed on the account. Possible values:
$account: The user object of the account being notified. Must contain at least the fields 'uid', 'name', and 'mail'.
$langcode: Optional language code to use for the notification, overriding account language.
The return value from drupal_mail_system()->mail(), if ends up being called.
function _user_mail_notify($op, $account, $langcode = NULL) {
// By default, we always notify except for canceled and blocked.
$notify = config('user.settings')
->get('notify.' . $op);
if ($notify || $op != 'status_canceled' && $op != 'status_blocked') {
$params['account'] = $account;
$langcode = $langcode ? $langcode : user_preferred_langcode($account);
$mail = drupal_mail('user', $op, $account->mail, $langcode, $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.
$site_mail = config('system.site')
->get('mail');
if (empty($site_mail)) {
$site_mail = ini_get('sendmail_from');
}
drupal_mail('user', 'register_pending_approval_admin', $site_mail, language_default()->langcode, $params);
}
}
return empty($mail) ? NULL : $mail['result'];
}