<?php
/**
 * TEMPORARY SMTP diagnostic. Upload alongside the other files, open it once in
 * your browser:  https://osce.skmcsimcenter.cloud/smtp-test.php
 * It sends one test email to your "from" address and reports success or the
 * exact error. No PHPMailer required — uses the built-in sender.
 *
 * IMPORTANT: DELETE this file from the server once it works. Setup only.
 */
header('Content-Type: text/plain; charset=utf-8');

$cfg = @include __DIR__ . '/smtp-config.php';
if (!is_array($cfg)) {
    exit("FAIL: smtp-config.php not found or invalid (must be named exactly smtp-config.php).\n");
}
require_once __DIR__ . '/smtp-send.php';

echo "Config loaded. Host={$cfg['host']} Port={$cfg['port']} Secure={$cfg['secure']} User={$cfg['username']}\n";
echo "Sending a test email to {$cfg['from_email']} ...\n\n";

$err = null;
$ok = osce_smtp_send(
    $cfg,
    $cfg['from_email'],                 // send the test to yourself
    'OSCE Nexus SMTP test',
    "If you can read this, SMTP works.\nYou can delete smtp-test.php now.\n",
    '',
    $err
);

if ($ok) {
    echo "SUCCESS: test email sent. Check the {$cfg['from_email']} inbox (and spam).\n";
    echo "Now DELETE smtp-test.php from the server.\n";
} else {
    echo "FAIL: {$err}\n\n";
    echo "Common fixes:\n";
    echo " - If it's a connection/timeout error: try port 587 with secure => 'tls'.\n";
    echo " - If it's an auth error (535): re-check the username/password.\n";
    echo " - If it's a TLS/certificate error: your host may use a different mail hostname.\n";
}
