You are here

function _auto_expire_notify in Auto Expire 7

Same name and namespace in other branches
  1. 5 auto_expire.module \_auto_expire_notify()

Sends out the notifications.

Parameters

$nid:

$mailkey:

$subject:

$body:

$args:

2 calls to _auto_expire_notify()
_auto_expire_notify_expired in ./auto_expire.module
Sets up the expired notification for expiry.
_auto_expire_notify_warning in ./auto_expire.module
Sets up the warning notification for expiry.

File

./auto_expire.module, line 629

Code

function _auto_expire_notify($nid, $mailkey, $subject, $body, $args) {
  if (!empty($subject)) {
    $select = db_select('users', 'u');
    $select
      ->fields('u', array(
      'mail',
    ));
    $select
      ->join('node', 'n', 'n.uid = u.uid');
    $select
      ->condition('n.nid', $nid, '=');
    $select
      ->condition('u.status', 1, '=');
    $select
      ->condition('u.uid', 0, '>');
    $result = $select
      ->execute()
      ->fetchField();
    if ($result) {
      $user_email = $result;

      //        $user_email = 'tester@test.test';
      $subject = t($subject, $args);
      $body = t($body, $args);
      $params = array(
        'subject' => $subject,
        'body' => $body,
      );
      $bcc = trim(variable_get(AUTO_EXPIRE_EMAIL . 'bcc', ''));
      if ($bcc == '') {
        $sent = drupal_mail('auto_expire', $mailkey, $user_email, language_default(), $params);
      }
      else {
        $params['bcc'] = $bcc;
        $sent = drupal_mail('auto_expire', $mailkey . '_bcc', $user_email, language_default(), $params);
      }
      if (!$sent) {
        watchdog('auto_expire', 'Could not send notification email to: %user_email', array(
          '%user_email' => $user_email,
          WATCHDOG_ERROR,
        ));
      }
    }
  }
}