| Current Path : /home/emeraadmin/public_html/pages/ |
| Current File : /home/emeraadmin/public_html/pages/emailUtils.php |
<?php
require __DIR__ . '/../vendor/autoload.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// Function to send email
function sendEmail($to, $subject, $body, $isHTML = true, $template = null, $placeholders = [])
{
$mail = new PHPMailer(true);
try {
// Server settings
$mail->isSMTP();
$mail->Host = 'localhost';
$mail->SMTPAuth = false;
$mail->SMTPAutoTLS = false;
$mail->Port = 25;
// Recipients
$mail->setFrom('mail@emerateamkids.com', 'emerateamkids.com'); // Replace with your GoDaddy email and name
$mail->addAddress($to);
// Load and process HTML email template if provided
if ($template) {
$emailTemplate = file_get_contents($template);
foreach ($placeholders as $key => $value) {
$emailTemplate = str_replace("[$key]", $value, $emailTemplate);
}
$body = $emailTemplate;
}
// Content
$mail->isHTML($isHTML);
$mail->Subject = $subject;
$mail->Body = $body;
$mail->send();
return "Email sent to $to";
} catch (Exception $e) {
return "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
?>