1.20.x user.module _user_mail_notify($op, $account, $language = NULL)

Conditionally create and send a notification email when a certain operation happens on the given user account.

Parameters

$op: The operation being performed on the account. Possible values:

  • 'register_admin_created': Welcome message for user created by the admin.
  • 'register_no_approval_required': Welcome message when user self-registers.
  • 'register_pending_approval': Welcome message, user pending admin approval.
  • 'password_reset': Password recovery request.
  • 'status_activated': Account activated.
  • 'status_blocked': Account blocked.
  • 'cancel_confirm': Account cancellation request.
  • 'status_canceled': Account canceled.

$account: The user object of the account being notified. Must contain at least the fields 'uid', 'name', and 'mail'.

$language: Optional language to use for the notification, overriding account language.

Return value

The return value from backdrop_mail_system()->mail(), if ends up being: called.

See also

user_mail_tokens()

backdrop_mail()

File

modules/user/user.module, line 2845
Enables the user registration and login system.

Code

function _user_mail_notify($op, $account, $language = NULL) {
  // We always notify unless specifically set otherwise. Canceled and blocked
  // are disabled by default, but everything else will notify. Not all options
  // have a checkbox in the UI.
  $default_notify = ($op != 'status_canceled' && $op != 'status_blocked');
  $config = config('system.core');
  $notify = $config->get('user_mail_' . $op . '_notify');
  $notify = isset($notify) ? $notify : $default_notify;
  if ($notify) {
    $params['account'] = $account;
    $language = $language ? $language : user_preferred_language($account);
    $mail = backdrop_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.
      $site_mail = $config->get('site_mail');
      if (empty($site_mail)) {
        $site_mail = ini_get('sendmail_from');
      }
      backdrop_mail('user', 'register_pending_approval_admin', $site_mail, language_default(), $params);

    }
  }
  return empty($mail) ? NULL : $mail['result'];
}