<?php
// admin/test-smtp.php
require_once __DIR__ . '/../config/config.php';
require_once __DIR__ . '/includes/EmailService.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $test_email = trim($_POST['test_email'] ?? '');
    if (empty($test_email)) {
        die("Please enter an email address.");
    }
    
    $emailService = new EmailService($pdo);
    $result = $emailService->sendTemplateEmail('system_notification', $test_email, [
        'user_name' => 'Admin Test'
    ]);
    
    if ($result) {
        echo "✅ Test email sent to " . htmlspecialchars($test_email);
    } else {
        echo "❌ Failed to send test email. Check your SMTP settings.";
    }
    exit();
} else {
    header("Location: email-management.php");
    exit();
}