You are here

function _inactive_user_mail in Inactive User 6

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

Wrapper for user_mail.

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

File

./inactive_user.module, line 443
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' => $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' => $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,
      );
      $user = user_load(array(
        'mail' => $recipient,
      ));
      $language = isset($user->uid) ? user_preferred_language($user) : language_default();
      drupal_mail('inactive_user', 'inactive_user_notice', $recipient, $language, $params, $from, TRUE);
    }
  }
}