Files
HotLunches/include/sendmail2.php
T
2026-10-19 15:22:52 -07:00

113 lines
3.8 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);
}
// 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 = "ezssoftware"; // SMTP server username
$mailObject->Password = "EZS2010@@"; // SMTP server password
$mailObject->CharSet = "UTF-8";
$mailObject->IsSendmail(); // tell the class to use Sendmail
$mailObject->ClearAddresses();
$mailObject->ClearAllRecipients();
$mailObject->ClearAttachments();
$emailSender = "mail@hotlunches.net";
$emailSenderName = $emailReply;
// $emailSenderName = "Hot Lunches Online";
$mailObject->AddReplyTo($emailFrom, $emailReply);
$mailObject->SetFrom($emailSender, $emailSenderName, 1);
$mailObject->Sender = $emailSender;
$mailObject->From = $emailSender;
$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);
}
$emailMessage = htmlspecialchars_decode($emailMessage,ENT_QUOTES);
$emailMessage = preg_replace("#&amp;#","&",$emailMessage);
// 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);
}
}
?>