You are here

function email_confirm_mail in Email Change Confirmation 5

Same name and namespace in other branches
  1. 6 email_confirm.module \email_confirm_mail()
  2. 7 email_confirm.module \email_confirm_mail()

Build and send out the confirmation email to the user's current and proposed new email address.

1 call to email_confirm_mail()
email_confirm_user in ./email_confirm.module
Implementation of hook_user().

File

./email_confirm.module, line 223

Code

function email_confirm_mail($edit) {
  global $user;
  $timestamp = time();
  $pass = $edit['pass'] ? md5($edit['pass']) : $user->pass;
  $hash = email_confirm_user_email_rehash($pass, $edit['mail']);
  $url = url('user/change-mail/' . $user->uid . '/' . $timestamp . '/' . $edit['mail'] . '/' . $hash, NULL, NULL, TRUE);
  $variables = array(
    '%name' => $user->name,
    '%site' => variable_get('site_name', 'drupal'),
    '%email_url' => $url,
  );
  $from = variable_get('email_confirm_confirmation_email_author', variable_get('site_mail', ini_get('sendmail_from')));
  $bcc = variable_get('email_confirm_confirmation_email_bcc', '');
  $subject = strtr(variable_get('email_confirm_confirmation_email_subject', t('Email address change request for %name at %site')), $variables);
  $body = strtr(variable_get('email_confirm_confirmation_email_body', t('Hello %name,

A request to change your email address has been made at %site.
You need to verify the change by clicking on the link below or by
copying and pasting it in your browser:

%email_url

This is a one-time URL - it can be used only once. It expires after
24 hours. If you do not click the link to confirm, your email address
at %site will not be updated.
')), $variables);
  $headers = array();
  if ($bcc) {
    $headers['Bcc'] = $bcc;
  }
  if ($success = drupal_mail('email_confirm_user_change_mail', $edit['mail'], $subject, $body, $from, $headers)) {
    $body = strtr(variable_get('email_confirm_confirmation_original_email_body', t('Hello %name,

A request to change your email address has been made at %site.
In order to confirm the update of your email address you will
need to follow the instructions sent to your new email address
within 24 hours.
')), $variables);
    drupal_mail('email_confirm_user_change_mail_original', $user->mail, $subject, $body, $from, $headers);
    drupal_set_message(t('A confirmation email has been sent to your new email address. You must follow the link provided in that email within 24 hours in order to confirm the change to your account email address.'));
  }
}