You are here

function pet_send_one_mail in Previewable email templates 7

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. 6 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 pet_reply_to (optional) The $params array may also contain data passed in by other modules. One use of this is for token substitution.

See also

hook_pet_substitutions_alter()

2 calls to pet_send_one_mail()
pet_action_send_pet in ./pet.rules.inc
Callback for eponymous rules action.
pet_send_mail in ./pet.module
Send tokenized email to a list of recipients.

File

./pet.module, line 398
Previewable Email Template module.

Code

function pet_send_one_mail($pet, $params) {
  $pet_logging = variable_get('pet_logging', 0);
  if (!pet_is_valid($pet)) {
    if ($pet_logging < 2) {
      watchdog('pet', 'Invalid PET object in pet_send_one_mail().', array(), WATCHDOG_ERROR);
    }
    else {
      drupal_set_message(t('Invalid PET object in pet_send_one_mail().'), 'error');
    }
    return;
  }
  if (empty($params['pet_from'])) {
    if ($pet_logging < 2) {
      watchdog('pet', 'Missing sender email address in pet_send_one_mail() for PET \'%name\'.', array(
        '%name' => $pet->name,
      ), WATCHDOG_ERROR);
    }
    else {
      drupal_set_message(t('Missing sender email address in pet_send_one_mail() for PET \'%name\'.', array(
        '%name' => $pet->name,
      )), 'error');
    }
    return;
  }
  if (empty($params['pet_to'])) {
    if ($pet_logging < 2) {
      watchdog('pet', 'Missing recipient email address in pet_send_one_mail() for PET \'%name\'.', array(
        '%name' => $pet->name,
      ), WATCHDOG_ERROR);
    }
    else {
      drupal_set_message(t('Missing recipient email address in pet_send_one_mail() for PET \'%name\'.', array(
        '%name' => $pet->name,
      )), 'error');
    }
    return;
  }
  if (isset($params['pet_reply_to'])) {
    $message['headers']['Reply-To'] = $params['pet_reply_to'];
  }
  $params['pet'] = $pet;
  $substitutions = pet_substitutions($pet, $params);
  $params['subject'] = token_replace($pet->subject, $substitutions, array(
    'clear' => TRUE,
  ));
  $params['body'] = token_replace($pet->mail_body, $substitutions, array(
    'clear' => TRUE,
  ));

  // Provided for Mime Mail module; alternate text-only form for multipart MIME
  $mail_body_plain = trim($pet->mail_body_plain);
  if (!empty($mail_body_plain)) {
    $params['plaintext'] = token_replace($pet->mail_body_plain, $substitutions, array(
      'clear' => TRUE,
    ));
  }

  // Provided for Mime Mail module; send ONLY plain text
  $params['plain'] = $pet->send_plain;
  $message = drupal_mail('pet', $pet->name, $params['pet_to'], language_default(), $params, $params['pet_from']);
  if ($message['send'] && $pet_logging == 0) {
    watchdog('pet', 'Successfully sent email to %recipient', array(
      '%recipient' => $params['pet_to'],
    ));
  }

  // return message, useful for show custom message, based email send status
  return $message;
}