You are here

function commerce_invoice_receipt_action_mail in Commerce Invoice Receipt 7

Same name and namespace in other branches
  1. 7.2 commerce_invoice_receipt.rules.inc \commerce_invoice_receipt_action_mail()
2 string references to 'commerce_invoice_receipt_action_mail'
commerce_invoice_receipt_rules_action_info in ./commerce_invoice_receipt.module
Implements hook_rules_action_info().
commerce_invoice_receipt_rules_action_info_alter in ./commerce_invoice_receipt.rules.inc
Implements hook_rules_action_info_alter().

File

./commerce_invoice_receipt.module, line 323
Provides a printable invoice receipt along with HTML mailing rules.

Code

function commerce_invoice_receipt_action_mail($order, $to, $subject, $from = NULL) {
  $to = str_replace(array(
    "\r",
    "\n",
  ), '', $to);
  $from = !empty($from) ? str_replace(array(
    "\r",
    "\n",
  ), '', $from) : NULL;
  $recipients = explode(',', $to);
  $params = array(
    'subject' => $subject,
    'order' => $order,
  );
  $account = user_load($order->uid);
  $language = user_preferred_language($account);
  foreach ($recipients as $recipient) {
    if ($recipient == '') {
      continue;
    }
    $message = drupal_mail('commerce_invoice_receipt', 'invoice', $recipient, $language, $params, $from);
    if ($message['result']) {
      watchdog('rules', 'Successfully sent email to %recipient', array(
        '%recipient' => $recipient,
      ));
    }
  }
}