function user_mail

Same name in other branches
  1. 7.x modules/user/user.module \user_mail()
  2. 8.9.x core/modules/user/user.module \user_mail()
  3. 10 core/modules/user/user.module \user_mail()

Implements hook_mail().

3 string references to 'user_mail'
ContactPersonalTest::testSendPersonalContactMessage in core/modules/contact/tests/src/Functional/ContactPersonalTest.php
Tests that mails for contact messages are correctly sent.
contact_mail in core/modules/contact/contact.module
Implements hook_mail().
MailHandlerTest::getSendMailMessages in core/modules/contact/tests/src/Unit/MailHandlerTest.php
Data provider for ::testSendMailMessages.

File

core/modules/user/user.module, line 778

Code

function user_mail($key, &$message, $params) {
    $token_service = \Drupal::token();
    $language_manager = \Drupal::languageManager();
    $langcode = $message['langcode'];
    $variables = [
        'user' => $params['account'],
    ];
    $language = $language_manager->getLanguage($langcode);
    $original_language = $language_manager->getConfigOverrideLanguage();
    $language_manager->setConfigOverrideLanguage($language);
    $mail_config = \Drupal::config('user.mail');
    $token_options = [
        'langcode' => $langcode,
        'callback' => 'user_mail_tokens',
        'clear' => TRUE,
    ];
    $message['subject'] .= PlainTextOutput::renderFromHtml($token_service->replace($mail_config->get($key . '.subject'), $variables, $token_options));
    $message['body'][] = $token_service->replace($mail_config->get($key . '.body'), $variables, $token_options);
    $language_manager->setConfigOverrideLanguage($original_language);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.