<?php
$workspace_path = "c:\\Users\\User\\Documents\\Antigravity Projects\\Apperal Managment System -Vanila- PHP";
chdir($workspace_path);

require_once 'includes/db.php';
require_once 'includes/email_helper.php';

$smtp = fetch("SELECT * FROM smtp_settings ORDER BY id DESC LIMIT 1");
if (!$smtp) {
    die("No SMTP settings in DB.\n");
}

echo "Testing connection to host: {$smtp['smtp_host']}:{$smtp['smtp_port']} with user: {$smtp['smtp_username']}\n";

try {
    // Send a test email to the username email address
    $to = $smtp['smtp_username'];
    $subject = "Live Test SMTP - Apparel System";
    $body = "<h1>SMTP Integration Work Completed</h1><p>The socket connection is functioning properly!</p>";
    $from_email = "test@companyprofile.com"; // Get from email address simulation
    $from_name = "Company Profile Name";
    
    send_smtp_email($to, $subject, $body, $from_email, $from_name, $smtp);
    echo "SUCCESS: Email sent successfully!\n";
} catch (Exception $e) {
    echo "ERROR: " . $e->getMessage() . "\n";
}
?>
