You are here

function uc_order_action_email in Ubercart 6.2

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

Sends an email concerning an order.

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

See also

uc_order_action_email_form()

1 string reference to 'uc_order_action_email'
uc_order_ca_action in uc_order/uc_order.ca.inc
Implements hook_ca_action().

File

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

Code

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

  // Token replacements for the from and recipient addresses
  $settings['replacements'] = array(
    'global' => NULL,
    'order' => $order,
    'user' => $account,
  );

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

  // Apply token replacements to recipient e-mail addresses.
  $addresses = token_replace_multiple($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;
    }
  }
  if (empty($recipients)) {
    watchdog('uc_order', 'Attempted to send an order e-mail with no recipient.', array(), WATCHDOG_ERROR);
    return;
  }
  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);
    }
  }
}