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

require_once __DIR__ . '/../libs/PHPMailer/Exception.php';
require_once __DIR__ . '/../libs/PHPMailer/PHPMailer.php';
require_once __DIR__ . '/../libs/PHPMailer/SMTP.php';

function send_mail(string $to, string $subject, string $body): bool {

  $mail = new PHPMailer(true);

  try {
    $mail->isSMTP();
    $mail->Host       = 'eliteguarantytrustinc.com';     // 🔴 CHANGE
    $mail->SMTPAuth   = true;
    $mail->Username   = 'info@eliteguarantytrustinc.com'; // 🔴 CHANGE
    $mail->Password   = 'Elite2025@';         // 🔴 CHANGE
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
    $mail->Port       = 465;

    $mail->setFrom('info@eliteguarantytrustinc.com', 'Elite Guarantytrust Inc');
    $mail->addAddress($to);

    $mail->isHTML(true);
    $mail->Subject = $subject;
    $mail->Body    = nl2br($body);

    return $mail->send();

  } catch (Exception $e) {
    error_log('MAIL ERROR: ' . $mail->ErrorInfo);
    return false;
  }
}
