You are here

function _inactive_user_mail in Inactive User 7

Same name and namespace in other branches
  1. 5 inactive_user.module \_inactive_user_mail()
  2. 6 inactive_user.module \_inactive_user_mail()

Wrapper for user_mail.

1 call to _inactive_user_mail()
inactive_user_cron in ./inactive_user.module
Implements hook_cron().

File

./inactive_user.module, line 681
The inactive user module controls inactive users.

Code

function _inactive_user_mail($subject, $message, $period, $user = NULL, $user_list = NULL) {
  global $base_url;
  if ($user_list) {
    $to = _inactive_user_admin_mail();
    $variables = array(
      '%period' => format_interval($period),
      '%sitename' => variable_get('site_name', 'drupal'),
      '%siteurl' => l($base_url, $base_url),
      "%userlist" => $user_list,
    );
  }
  elseif (isset($user->uid)) {
    $to = $user->mail;
    $variables = array(
      '%username' => $user->name,
      '%useremail' => $user->mail,
      '%lastaccess' => empty($user->access) ? t('never') : format_date($user->access, 'custom', 'M d, Y'),
      '%period' => format_interval($period),
      '%sitename' => variable_get('site_name', 'drupal'),
      '%siteurl' => l($base_url, $base_url),
    );
  }
  if (isset($to)) {
    $from = variable_get('site_mail', ini_get('sendmail_from'));
    $headers = array(
      'Reply-to' => $from,
      'Return-path' => "<{$from}>",
      'Errors-to' => $from,
    );
    $recipients = explode(',', $to);
    foreach ($recipients as $recipient) {
      $recipient = trim($recipient);
      $params = array(
        'subject' => $subject,
        'message' => strtr($message, $variables),
        'headers' => $headers,
      );
      $users = user_load_multiple(array(), array(
        'mail' => $recipient,
      ));
      $user = array_shift($users);
      $language = isset($user->uid) ? user_preferred_language($user) : language_default();
      drupal_mail('inactive_user', 'inactive_user_notice', $recipient, $language, $params, $from, TRUE);
    }
  }
}