You are here

function user_register_notify_mail in User registration notification 7

Same name and namespace in other branches
  1. 6 user_register_notify.module \user_register_notify_mail()

Implements hook_mail().

File

./user_register_notify.module, line 154
Installation file for the user_register_notify module.

Code

function user_register_notify_mail($key, &$message, $params) {
  $data['user'] = $params['account'];
  $langcode = $message['language']->language;
  $subject = '';
  $body = '';
  switch ($key) {
    case 'admin_create':
      $subject = t(variable_get('user_register_notify_created_subject', t('Account details for [user:name] at [site:name]')), array(), array(
        'langcode' => $langcode,
      ));
      $body = t(variable_get('user_register_notify_created_body', t("User [user:name] ([user:url]) has created account.\n\nEdit user: [user:edit-url]\n\nDelete user: [user:cancel-url]\n\nUser status: [user:status]")), array(), array(
        'langcode' => $langcode,
      ));
      break;
    case 'admin_delete':
      $subject = t(variable_get('user_register_notify_deleted_subject', t('Account details for [user:name] at [site:name]')), array(), array(
        'langcode' => $langcode,
      ));
      $body = t(variable_get('user_register_notify_deleted_body', t("User [user:name] ([user:url]) has deleted account.")), array(), array(
        'langcode' => $langcode,
      ));
      break;
    case 'admin_update':
      $subject = t(variable_get('user_register_notify_updated_subject', t('Account details for [user:name] at [site:name]')), array(), array(
        'langcode' => $langcode,
      ));
      $body = t(variable_get('user_register_notify_updated_body', t("User [user:name] ([user:url]) has updated account.\n\nEdit user: [user:edit-url]\n\nDelete user: [user:cancel-url]")), array(), array(
        'langcode' => $langcode,
      ));
      break;
  }

  // We do not sanitize the token replacement, since the output of this
  // replacement is intended for an e-mail message, not a web browser.
  $message['subject'] = token_replace($subject, array(
    'user' => $data['user'],
  ), array(
    'language' => $message['language'],
    'sanitize' => FALSE,
    'clear' => TRUE,
  ));
  $message['body'][] = token_replace($body, array(
    'user' => $data['user'],
  ), array(
    'language' => $message['language'],
    'callback' => 'user_mail_tokens',
    'sanitize' => FALSE,
    'clear' => TRUE,
  ));
}