116 lines
3.9 KiB
PHP
116 lines
3.9 KiB
PHP
<?php
|
|
|
|
//
|
|
// Include to setup the phpmailer class and send a message
|
|
//
|
|
|
|
include_once "class.phpmailer.php";
|
|
|
|
if (!function_exists('SendEmail')) {
|
|
function SendEmail($emailTo, $emailFrom, $emailSubject, $emailMessage, $emailReply = "", $emailRecipient = "", $attachments = array(), $templateFile = "") {
|
|
global $error_message, $ApplicationURLS;
|
|
|
|
// Perform some basic validation on the email addresses
|
|
if (strlen($emailTo) == 0) {
|
|
$error_message = "emailTo not defined";
|
|
return(0);
|
|
}
|
|
if (strlen($emailFrom) == 0) {
|
|
$error_message = "emailFrom not defined";
|
|
return(0);
|
|
}
|
|
|
|
$emailTo = str_replace(" ","",$emailTo);
|
|
$emailTo = str_replace(",",".",$emailTo);
|
|
|
|
$emailFrom = str_replace(" ","",$emailFrom);
|
|
$emailFrom = str_replace(",",".",$emailFrom);
|
|
|
|
if (!preg_match("/^[^@]+@[a-z0-9-]+(\.[a-z0-9-]{2,40}){1,4}$/",$emailTo)) {
|
|
$error_message = "emailTo bad format";
|
|
return(0);
|
|
}
|
|
if (!preg_match("/^[^@]+@[a-z0-9-]+(\.[a-z0-9-]{2,40}){1,4}$/",$emailFrom)) {
|
|
$error_message = "emailFrom bad format";
|
|
return(0);
|
|
}
|
|
|
|
// Validate sending domain
|
|
$match = false;
|
|
for ($i = 0; $i < count($ApplicationURLS); $i++) {
|
|
$url = $ApplicationURLS[$i]['url'];
|
|
if (strpos($emailFrom, "@$url")) $match = true;
|
|
}
|
|
|
|
$senderEmail = $emailFrom;
|
|
if (!$match) $senderEmail = "noreply@ezssoftware.com";
|
|
|
|
|
|
// Create and configure the mail object
|
|
$mailObject = new PHPMailer(false); //New instance, with exceptions disabled
|
|
|
|
$mailObject->SMTPAuth = true; // enable SMTP authentication
|
|
$mailObject->Port = 25; // set the SMTP server port
|
|
$mailObject->Host = "localhost"; // SMTP server
|
|
$mailObject->Username = "schoolappointments"; // SMTP server username
|
|
$mailObject->Password = "Online3214++.."; // SMTP server password
|
|
$mailObject->CharSet = "UTF-8";
|
|
|
|
$mailObject->IsSendmail(); // tell the class to use Sendmail
|
|
|
|
$mailObject->ClearAddresses();
|
|
$mailObject->ClearAllRecipients();
|
|
$mailObject->ClearAttachments();
|
|
|
|
$mailObject->AddReplyTo($emailFrom, $emailReply);
|
|
$mailObject->SetFrom($senderEmail, $emailReply, 1);
|
|
$mailObject->Sender = $senderEmail;
|
|
$mailObject->From = $senderEmail;
|
|
|
|
$mailObject->AddAddress($emailTo, $emailRecipient);
|
|
$mailObject->Subject = $emailSubject;
|
|
|
|
$mailObject->IsMail(); // tell the class to use Mail
|
|
$mailObject->IsSMTP(); // tell the class to use SMTP
|
|
$mailObject->IsSendmail(); // tell the class to use SendMail
|
|
|
|
// Process a template if one is passed
|
|
if (isset($templateFile) && strlen($templateFile) && is_file($templateFile)) {
|
|
$template = file_get_contents($templateFile);
|
|
}
|
|
|
|
// Use template if available
|
|
if (isset($template) && strlen($template)) {
|
|
$Message = str_replace("{EMAIL_BODY_TEXT}",$emailMessage,$template);
|
|
$mailObject->MsgHTML($Message);
|
|
}
|
|
else {
|
|
if (strip_tags($emailMessage) == $emailMessage) {
|
|
// Send as a plain text message
|
|
$mailObject->Body = $emailMessage;
|
|
}
|
|
else {
|
|
// Send HTML message
|
|
$mailObject->MsgHTML($emailMessage);
|
|
}
|
|
}
|
|
|
|
// Attach any attachments
|
|
if (is_array($attachments) && count($attachments) > 0) {
|
|
for ($i = 0; $i < count($attachments); $i++) {
|
|
$file = $attachments[$i];
|
|
if (is_file($file)) {
|
|
$mailObject->AddAttachment($file);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Send message
|
|
$mailObject->Send();
|
|
|
|
return(1);
|
|
}
|
|
}
|
|
|
|
?>
|