You are here

function uc_file_action_order_email in Ubercart 6.2

Same name and namespace in other branches
  1. 8.4 uc_file/uc_file.rules.inc \uc_file_action_order_email()
  2. 7.3 uc_file/uc_file.rules.inc \uc_file_action_order_email()

Sends an email with order and file replacement tokens.

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

See also

uc_file_action_order_email_form()

1 string reference to 'uc_file_action_order_email'
uc_file_ca_action in uc_file/uc_file.ca.inc
Implements hook_ca_action().

File

uc_file/uc_file.ca.inc, line 168
This file contains the Conditional Actions hooks and functions necessary to make the file-related entity, conditions, events, and actions work.

Code

function uc_file_action_order_email($order, $file_expiration, $settings) {
  $account = uc_order_user_load($order);

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

  // Replace tokens and parse recipients.
  $recipients = array();
  $addresses = token_replace_multiple($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('ca', 'Attempt to e-mail @email concerning order @order_id failed.', array(
        '@email' => $email,
        '@order_id' => $order->order_id,
      ), WATCHDOG_ERROR);
    }
  }
}