75 lines
2.4 KiB
PHP
75 lines
2.4 KiB
PHP
<?php
|
|
|
|
require_once("table.php");
|
|
|
|
//
|
|
// Include to add email messages to the mail queue
|
|
//
|
|
|
|
if (!function_exists('QueueEmail')) {
|
|
function QueueEmail($email_to, $email_from, $email_subject, $email_message, $email_from_name = "", $email_to_name = "", $attachmentFiles = array(), $template_file = "", $batch_id = 0) {
|
|
|
|
global $school_num;
|
|
global $QueueDelay;
|
|
|
|
$emailq = new Table("email_queue");
|
|
|
|
// Perform some basic validation on the email addresses
|
|
if (strlen($email_to) == 0) return(0);
|
|
if (strlen($email_from) == 0) return(0);
|
|
|
|
$email_to = str_replace(" ","",$email_to);
|
|
$email_to = str_replace(",",".",$email_to);
|
|
$email_to = strtolower($email_to);
|
|
|
|
$email_from = str_replace(" ","",$email_from);
|
|
$email_from = str_replace(",",".",$email_from);
|
|
$email_from = strtolower($email_from);
|
|
|
|
if (preg_match("/^[^@]+@[a-z0-9-]+(\.[a-z0-9-]{2,40}){1,4}$/",$email_to) === FALSE) return(0);
|
|
if (preg_match("/^[^@]+@[a-z0-9-]+(\.[a-z0-9-]{2,40}){1,4}$/",$email_from) === FALSE) return(0);
|
|
|
|
|
|
// Process any attachments
|
|
$attachments = "";
|
|
if (is_array($attachmentFiles) && count($attachmentFiles) > 0) {
|
|
for ($i = 0; $i < count($attachmentFiles); $i++) {
|
|
$file = $attachmentFiles[$i];
|
|
if (is_file($file)) {
|
|
if (strlen($attachments)) $attachments .= "\n";
|
|
$attachments .= $file;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!is_array($attachmentFiles) && strlen($attachmentFiles)) $attachments = $attachmentFiles;
|
|
|
|
|
|
// Setup parameters
|
|
$entry = array();
|
|
$entry['status'] = 'Queued';
|
|
$entry['posted_time'] = time();
|
|
$entry['posted_date_time'] = date("Y-m-d H:i:s",$entry['posted_time']);
|
|
$entry['batch_id'] = $batch_id;
|
|
$entry['delay'] = $QueueDelay;
|
|
$entry['school_num'] = $school_num;
|
|
$entry['email_to'] = $email_to;
|
|
$entry['email_from'] = $email_from;
|
|
$entry['email_subject'] = $email_subject;
|
|
$entry['email_message'] = $email_message;
|
|
$entry['email_from_name'] = $email_from_name;
|
|
$entry['email_to_name'] = $email_to_name;
|
|
$entry['attachments'] = $attachments;
|
|
$entry['template_file'] = $template_file;
|
|
|
|
// Queue message
|
|
$query = $emailq->BuildInsert($entry);
|
|
$query = preg_replace("#&#","&",$query);
|
|
db_query($query);
|
|
|
|
return(1);
|
|
}
|
|
}
|
|
|
|
?>
|