function _user_mail_notify

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'.

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

Return value

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

See also

user_mail_tokens()

drupal_mail()

5 calls to _user_mail_notify()
RegisterFormController::save in drupal/core/modules/user/lib/Drupal/user/RegisterFormController.php
Overrides Drupal\Core\Entity\EntityFormController::submit().
UserStorageController::postSave in drupal/core/modules/user/lib/Drupal/user/UserStorageController.php
Overrides Drupal\Core\Entity\DatabaseStorageController::postSave().
user_cancel_confirm_form_submit in drupal/core/modules/user/user.pages.inc
Submit handler for the account cancellation confirm form.
user_pass_submit in drupal/core/modules/user/user.pages.inc
_user_cancel in drupal/core/modules/user/user.module
Last batch processing step for cancelling a user account.

File

drupal/core/modules/user/user.module, line 2725
Enables the user registration and login system.

Code

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'];
}