<?php
/**
 * TEMPORARY mail() diagnostic for cPanel. Open once in your browser:
 *   https://osce.skmcsimcenter.cloud/mail-test.php?to=you@example.com
 * Sends a test through the server's local mail system (Exim) — the route that
 * works even when outbound SMTP sockets are firewalled.
 *
 * DELETE this file once mail is confirmed working.
 */
header('Content-Type: text/plain; charset=utf-8');

// Where to send the test. Default to the ticket recipient; override with ?to=
$to = isset($_GET['to']) ? trim($_GET['to']) : 'ac@adresponder.site';
if (!filter_var($to, FILTER_VALIDATE_EMAIL)) {
    exit("Bad ?to= address.\n");
}

// From MUST be on a domain hosted on THIS server so SPF/DKIM pass.
$from    = 'noreply@osce.skmcsimcenter.cloud';
$subject = '=?UTF-8?B?' . base64_encode('OSCE Nexus mail() test') . '?=';
$body    = "If you can read this, PHP mail() works on this server.\n"
         . "You can delete mail-test.php now.\n";
$headers = "From: OSCE Nexus <{$from}>\r\n"
         . "MIME-Version: 1.0\r\n"
         . "Content-Type: text/plain; charset=UTF-8\r\n";

echo "Sending test mail\n  from: {$from}\n  to:   {$to}\n\n";

if (!function_exists('mail')) {
    exit("FAIL: PHP mail() is disabled on this host.\n");
}

$ok = mail($to, $subject, $body, $headers, '-f' . $from);

if ($ok) {
    echo "ACCEPTED: the server accepted the message for delivery.\n";
    echo "Check the {$to} inbox AND its spam folder in a minute.\n";
    echo "If it arrives -> we'll switch the form to mail(). Then delete this file.\n";
} else {
    echo "FAIL: mail() returned false (the local mail system rejected it).\n";
}
