<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require __DIR__ . '/../libs/PHPMailer/src/Exception.php';
require __DIR__ . '/../libs/PHPMailer/src/PHPMailer.php';
require __DIR__ . '/../libs/PHPMailer/src/SMTP.php';

function sendEmail($to, $subject, $body){

    $mail = new PHPMailer(true);

    try {

        // SMTP SETTINGS (CHANGE THIS)
        $mail->isSMTP();
        $mail->Host       = 'mail.edmsolutions.co.za';
        $mail->SMTPAuth   = true;
        $mail->Username   = 'noreply@edmsolutions.co.za';
        $mail->Password   = 'noreply@1986';
        $mail->SMTPSecure = 'tls';
        $mail->Port       = 587;

        // FROM
        $mail->setFrom('noreply@edmsolutions.co.za', 'InfraCore™');

        // TO
        $mail->addAddress($to);

        // CONTENT
       $mail->isHTML(true);
$mail->CharSet = 'UTF-8';   // ✅ ADD THIS LINE
$mail->Subject = $subject;
$mail->Body    = $body;

        $mail->send();

    } catch (Exception $e) {
        error_log("Email failed: " . $mail->ErrorInfo);
    }
}