<?php

require_once __DIR__ . '/vendor/autoload.php';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

$mail = new PHPMailer(true);

try {
    // 🔥 Enable debug (very important for testing)
    $mail->SMTPDebug = 2;

    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com';
    $mail->SMTPAuth = true;

    $mail->Username = 'aphachanthavong@gmail.com'; // CHANGE
    $mail->Password = 'ipxtvjithrxeacgc';   // CHANGE

    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
    $mail->Port = 587;

    $mail->setFrom('yourgmail@gmail.com', 'DocuTrack Test');
    $mail->addAddress('yourgmail@gmail.com'); // send to yourself

    $mail->isHTML(true);
    $mail->Subject = 'Test Email from DocuTrack';
    $mail->Body = '<h2>✅ Email is working!</h2><p>This is a test email.</p>';

    $mail->send();

    echo "✅ Email sent successfully!";
} catch (Exception $e) {
    echo "❌ Error: " . $mail->ErrorInfo;
}