You are here

function pet_send_one_mail in Previewable email templates 6

Same name and namespace in other branches
  1. 8.4 pet.module \pet_send_one_mail()
  2. 8 pet.module \pet_send_one_mail()
  3. 7 pet.module \pet_send_one_mail()

Send one email, with token substitution.

This may be called directly from other modules.

Parameters

$pet: The loaded PET object to use for the email @see pet_load()

$params: Array of parameters used when constructing the email. pet_from (required) - a valid sender email address pet_to (required) - a valid recipient email address pet_recipients (optional) - if called from pet_send_mail() will contain the full recipient list pet_uid (optional) - if provided, a valid user id for 'user' type token substitution pet_nid (optional) - if provided, a valid node id for 'node' type token substitution The $params array may also contain data passed in by other modules. One use of this is for token substitution. @see pet_substitutions() @see hook_pet_substitutions_alter()

2 calls to pet_send_one_mail()
pet_action_email in ./pet.module
Sends an email related to an Ubercart order, triggered by a conditional action.
pet_send_mail in ./pet.module
Send tokenized email to each recipient. Called once form passes validation. Can also be called directly from code.

File

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

Code

function pet_send_one_mail($pet, $params) {
  if (!pet_is_valid($pet)) {
    watchdog('pet', 'Invalid PET object in pet_send_one_mail().', array(), WATCHDOG_ERROR);
    return;
  }
  if (empty($params['pet_from'])) {
    watchdog('pet', 'Missing sender email address in pet_send_one_mail() for PET \'%name\'.', array(
      '%name' => $pet->name,
    ), WATCHDOG_ERROR);
    return;
  }
  if (empty($params['pet_to'])) {
    watchdog('pet', 'Missing recipient email address in pet_send_one_mail() for PET \'%name\'.', array(
      '%name' => $pet->name,
    ), WATCHDOG_ERROR);
    return;
  }
  $params['pet'] = $pet;
  $substitutions = pet_substitutions($pet, $params);
  $params['subject'] = token_replace_multiple($pet->subject, $substitutions);
  $params['body'] = token_replace_multiple($pet->body, $substitutions);
  drupal_mail('pet', $pet->name, $params['pet_to'], language_default(), $params, $params['pet_from']);
}