<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

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

define('BASEPATH', true); // Dummy define to allow direct execution
define('APPPATH', __DIR__ . '/application/');

require_once APPPATH.'third_party/PHPMailer/Exception.php';
require_once APPPATH.'third_party/PHPMailer/PHPMailer.php';
require_once APPPATH.'third_party/PHPMailer/SMTP.php';

$mail = new PHPMailer(true);

try {
    $mail->SMTPDebug = 4; // Enable verbose debug output
    $mail->Debugoutput = 'html'; // Output as HTML

    $mail->isSMTP();
    $mail->Host       = 'smtp.gmail.com';
    $mail->SMTPAuth   = true;
    $mail->Username   = 'kishanpatel4594@gmail.com';
    $mail->Password   = 'iwvqkbtsduxdmqwp';
    $mail->SMTPSecure = 'tls';
    $mail->Port       = 587;
    $mail->CharSet    = 'UTF-8';

    $mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
        )
    );

    $mail->setFrom('kishanpatel4594@gmail.com', 'Synergy Hospital');
    $mail->addAddress('kishanpatel4594@gmail.com');

    $mail->isHTML(true);
    $mail->Subject = 'Test Email From Synergy Hospital';
    $mail->Body    = 'This is a test email sent directly from test_mail.php to verify SMTP connection.';

    echo "<h3>Starting SMTP Connection Test...</h3>";
    $mail->send();
    echo "<h3 style='color:green;'>Email Sent Successfully!</h3>";
} catch (Exception $e) {
    echo "<h3 style='color:red;'>PHPMailer Error: {$mail->ErrorInfo}</h3>";
}
