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

require 'mail/PHPMailer.php';
require 'mail/SMTP.php';
require 'mail/Exception.php';

$mail = new PHPMailer(true);

try {
    // Server settings
    $mail->isSMTP();
    $mail->Host       = 'smtp.gmail.com';
    $mail->Port       = 587;
    $mail->SMTPAuth   = true;
    $mail->Username   = 'king.nmeso@gmail.com';
    $mail->Password   = 'tovy lqce ylzp knbg'; // Zoho App Password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Use STARTTLS encryption
    //$mail->Timeout    = 30;
    
    // Debug output (optional, remove in production)
    $mail->SMTPDebug  = SMTP::DEBUG_CONNECTION; 
    $mail->Debugoutput = function($str, $level) { echo $str . "<br>"; };

    // Recipients
    $mail->setFrom('king.nmeso@gmail.com', 'Airex Service');
    $mail->addAddress('king.nmeso@gmail.com', 'King Nmeso');

    // Content
    $mail->isHTML(true);
    $mail->Subject = 'Zoho SMTP Test Mail';
    $mail->Body    = '<h3>This is a test email from Airex Service (Zoho SMTP)</h3><p>✅ It worked!</p>';
    $mail->AltBody = 'This is a plain text version of the test email.';

    $mail->send();
    echo '<br>✅ Email sent successfully to king.nmeso@gmail.com';
} catch (Exception $e) {
    echo "<br>❌ Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>