function pet_send_mail in Previewable email templates 6
Same name and namespace in other branches
- 8.4 pet.module \pet_send_mail()
- 8 pet.module \pet_send_mail()
- 7 pet.module \pet_send_mail()
Send tokenized email to each recipient. Called once form passes validation. Can also be called directly from code.
Parameters
$name: The unique name of the PET template.
$recipients: An array of at least one recipient in one of two formats: 1. a simple email address, in which case the uid is looked up 2. an array('mail' => <email address>, 'uid' => <uid>) in which case the uid is already available
$nid: An optional node id for token substitutions.
$subject: An optional subject which if provided will override the subject in the PET.
$body: An optional body which if provided which will override the body in the PET.
$from: An optional from email which if provided which will override the from in the PET (which overrides the site default).
$cc: Optional cc emails which if provided which will override the cc's in the PET.
$bcc: Optional bcc emails which if provided which will override the bcc's in the PET.
1 call to pet_send_mail()
- pet_user_form_submit in ./
pet.admin.inc - Form submission. Take action on step 2 (confirmation of the populated templates).
File
- ./
pet.module, line 166 - Previewable E-mail Template module.
Code
function pet_send_mail($name, $recipients, $nid = NULL, $subject = NULL, $body = NULL, $from = NULL, $cc = NULL, $bcc = NULL) {
$pet = pet_load($name);
if (!$pet) {
watchdog('pet', 'Unable to load PET %name.', array(
'%name' => $name,
), WATCHDOG_ERROR);
return;
}
if (!is_array($recipients) || count($recipients) < 1) {
watchdog('pet', 'At least one recipient must be provided for PET %name.', array(
'%name' => $name,
), WATCHDOG_NOTICE);
return;
}
// Override subject and body if necessary
$pet->subject = $subject ? $subject : $pet->subject;
$pet->body = $body ? $body : $pet->body;
// Store data in params in case a module wants to act on them somehow
$params['pet_recipients'] = $recipients;
$params['pet_nid'] = $nid;
$params['pet_from'] = $from ? $from : ($pet->from_override ? $pet->from_override : variable_get('site_mail', $GLOBALS['site_mail']));
$params['pet_cc'] = pet_parse_mails($cc);
$params['pet_bcc'] = pet_parse_mails($bcc);
foreach ($recipients as $recipient) {
if (is_array($recipient)) {
$params['pet_to'] = $recipient['mail'];
$params['pet_uid'] = $recipient['uid'];
}
else {
// Strip leading uid for backward compatability
$mail = preg_replace('/^[0-9]*\\|/', '', $recipient);
$params['pet_to'] = $mail;
$params['pet_uid'] = pet_lookup_uid($mail);
}
pet_send_one_mail($pet, $params);
}
}