You are here

function uc_order_action_email in Ubercart 7.3

Same name and namespace in other branches
  1. 8.4 uc_order/uc_order.rules.inc \uc_order_action_email()
  2. 6.2 uc_order/uc_order.ca.inc \uc_order_action_email()

Sends an email concerning an order.

The 'Sender', 'Recipients', 'Subject', and 'Message' fields accept order token replacements.

See also

uc_order_action_email_form()

1 string reference to 'uc_order_action_email'
uc_order_rules_action_info in uc_order/uc_order.rules.inc
Implements hook_rules_action_info().

File

uc_order/uc_order.rules.inc, line 733
Hooks and functions for uc_order Rules integration.

Code

function uc_order_action_email($order, $from, $addresses, $subject, $message, $format) {
  $settings = array(
    'from' => $from,
    'addresses' => $addresses,
    'subject' => $subject,
    'message' => $message,
    'format' => $format,
  );

  // Token replacements for the subject and body.
  $settings['replacements'] = array(
    'uc_order' => $order,
  );

  // Apply token replacements to the 'from' e-mail address.
  $from = token_replace($settings['from'], $settings['replacements']);
  if (empty($from)) {
    $from = uc_store_email_from();
  }

  // Apply token replacements to 'recipient' e-mail addresses.
  $addresses = token_replace($settings['addresses'], $settings['replacements']);

  // Split up our recipient e-mail addresses.
  $recipients = array();
  foreach (explode("\n", $addresses) as $address) {
    $address = trim($address);

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