You are here

function uc_recurring_renewal_email in UC Recurring Payments and Subscriptions 7.2

Send an email with order and recurring fee replacement tokens.

The recipients, subject, and message fields take order token replacements.

2 string references to 'uc_recurring_renewal_email'
uc_recurring_ca_predicate in ./uc_recurring.ca.inc
Implements hook_ca_predicate().
uc_recurring_default_rules_configuration in ./uc_recurring.rules_defaults.inc
Implements hook_default_rules_configuration().

File

./uc_recurring.rules.inc, line 207
Rules definitions.

Code

function uc_recurring_renewal_email($order, $recurring_fee, $from, $addresses, $subject, $message, $format) {
  $settings = array(
    'from' => $from,
    'addresses' => $addresses,
    'subject' => $subject,
    'message' => $message,
    'format' => $format,
  );
  $account = uc_order_user_load($order);

  // Token replacements for the subject and body
  $settings['replacements'] = array(
    'global' => NULL,
    'order' => $order,
    'user' => $account,
    'recurring_fee' => $recurring_fee,
  );

  // Replace tokens and parse recipients.
  $recipients = array();
  $addresses = token_replace($settings['addresses'], $settings['replacements']);
  foreach (explode("\n", $addresses) as $address) {
    $recipients[] = trim($address);
  }

  // Send to each recipient.
  foreach ($recipients as $email) {
    $sent = drupal_mail('uc_order', 'action-mail', $email, uc_store_mail_recipient_language($email), $settings, $settings['from']);
    if (!$sent['result']) {
      watchdog('uc_recurring', 'Attempt to e-mail @email concerning order @order_id failed.', array(
        '@email' => $email,
        '@order_id' => $order->order_id,
      ), WATCHDOG_ERROR);
    }
  }
}