You are here

function pet_action_email in Previewable email templates 6

Sends an email related to an Ubercart order, triggered by a conditional action.

See also

pet_action_email_form()

1 string reference to 'pet_action_email'
pet_ca_action in ./pet.module
Implementation of hook_ca_action().

File

./pet.module, line 348
Previewable E-mail Template module.

Code

function pet_action_email($order, $settings) {

  // Token replacements for the from and recipient addresses
  $account = uc_order_user_load($order);
  $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']);
  $from = empty($from) ? uc_store_email_from() : $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;
    }
  }

  // Load the PET and send emails
  $pet = pet_load($settings['pet']);
  $params = array(
    'pet_from' => $from,
    'uc_order' => $order,
  );
  foreach ($recipients as $email) {
    $params['pet_to'] = $email;
    $params['pet_uid'] = $account->uid;
    pet_send_one_mail($pet, $params);
  }
}