You are here

function uc_order_action_email_invoice in Ubercart 7.3

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

Emails an invoice.

The 'Sender', 'Subject' and 'Addresses' fields take order token replacements.

1 string reference to 'uc_order_action_email_invoice'
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 794
Hooks and functions for uc_order Rules integration.

Code

function uc_order_action_email_invoice($order, $from, $addresses, $subject, $template, $view) {
  $settings = array(
    'from' => $from,
    'addresses' => $addresses,
    'subject' => $subject,
    'template' => $template,
    'view' => $view,
  );

  // Token replacements for the from, 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;
    }
  }
  $settings['message'] = theme('uc_order', array(
    'order' => $order,
    'op' => $settings['view'],
    'template' => $settings['template'],
  ));
  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 invoice for order @order_id to @email failed.', array(
        '@email' => $email,
        '@order_id' => $order->order_id,
      ), WATCHDOG_ERROR);
    }
  }
}