You are here

function user_email_verification_mail in User email verification 7

Same name and namespace in other branches
  1. 8 user_email_verification.module \user_email_verification_mail()

Implements hook_mail().

File

./user_email_verification.module, line 432
This module allows you to have e-mail verification and in meanwhile allowing the users to type their own passwords. If they do not verify their accounts in a certain time interval the user will be blocked.

Code

function user_email_verification_mail($key, &$message, $params) {
  $language = $message['language'];
  if ($key == 'verify') {
    $subject = t(variable_get('user_email_verification_subject', 'Verification e-mail'), [], [
      'langcode' => $language->language,
    ]);
    $body = t(variable_get('user_email_verification_body', 'Please verify your e-mail by following the link: [user:verify-email]'), [], [
      'langcode' => $language->language,
    ]);
    if (module_exists('i18n_variable')) {

      // If i18n_variable module is used: get the text variables directly and
      // not from the cache, because the language might not match the current
      // $language here.
      $subject_translated = i18n_variable_get('user_email_verification_subject', $language->language, NULL);

      // i18n_variable_get returns nothing if the realm is not set.
      if (!is_null($subject_translated)) {

        // Use translated value.
        $subject = $subject_translated;
      }
      $body_translated = i18n_variable_get('user_email_verification_body', $language->language, NULL);

      // i18n_variable_get returns nothing if the realm is not set.
      if (!is_null($body_translated)) {

        // Use translated value.
        $body = $body_translated;
      }
    }
    $message['subject'] .= $subject;
    $message['body'][] = $body;
  }
  if ($key == 'verify_blocked') {
    $account = $params['account'];
    $message['subject'] .= t('A blocked account verified his e-mail.');
    $message['body'][] = t('A blocked account ID: @AID verified his e-mail. If the account is not blocked for other reason, please unblock the account.');
  }
  if ($key == 'verify_extended') {
    $account = $params['account'];
    $message['subject'] .= variable_get('user_email_verification_extended_subject', t('Account blocked, please verify e-mail address'));
    $message['body'][] = variable_get('user_email_verification_extended_body', t('Your account is now blocked. Your e-mail may still be verified by following the link: [user:verify-email-extended]'));
  }
}