function _user_mail_notify

You are here

7 user.module _user_mail_notify($op, $account, $language = NULL)
6 user.module _user_mail_notify($op, $account, $language = NULL)
8 user.module _user_mail_notify($op, $account, $langcode = NULL)

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:

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



5 calls to _user_mail_notify()
RegisterFormController::save in core/modules/user/lib/Drupal/user/RegisterFormController.php
Overrides Drupal\Core\Entity\EntityFormController::submit().
User::postSave in core/modules/user/lib/Drupal/user/Entity/User.php
Acts on a saved entity before the insert or update hook is invoked.
UserCancelForm::submit in core/modules/user/lib/Drupal/user/Form/UserCancelForm.php
This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be passed to the following submit handlers. At this point of the form workflow the entity is validated and the form…
UserPasswordForm::submitForm in core/modules/user/lib/Drupal/user/Form/UserPasswordForm.php
Form submission handler.
_user_cancel in core/modules/user/user.module
Last batch processing step for cancelling a user account.


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


function _user_mail_notify($op, $account, $langcode = NULL) {
  // By default, we always notify except for canceled and blocked.
  $notify = \Drupal::config('user.settings')->get('notify.' . $op);
  if ($notify || ($op != 'status_canceled' && $op != 'status_blocked')) {
    $params['account'] = $account;
    $langcode = $langcode ? $langcode : $account->getPreferredLangcode();
    // Get the custom site notification email to use as the from email address
    // if it has been set.
    $site_mail = \Drupal::config('')->get('mail_notification');
    // If the custom site notification email has not been set, we use the site
    // default for this.
    if (empty($site_mail)) {
      $site_mail = \Drupal::config('')->get('mail');
    if (empty($site_mail)) {
      $site_mail = ini_get('sendmail_from');
    $mail = drupal_mail('user', $op, $account->getEmail(), $langcode, $params, $site_mail);
    if ($op == 'register_pending_approval') {
      // If a user registered requiring admin approval, notify the admin, too.
      // We use the site default language for this.
      drupal_mail('user', 'register_pending_approval_admin', $site_mail, \Drupal::languageManager()->getDefaultLanguage()->id, $params);
  return empty($mail) ? NULL : $mail['result'];