<?php
$message = "";

if(isset($_POST['send'])) {

    $to = $_POST['email'];
    $orderid = $_POST['orderid'];

    if(empty($orderid)){
        $orderid = "N/A";
    }

    $subject = "Test Mail from Domain Server";

    $body = "
    Hello,

    This is a test email from your Domain server.

    REPORT ID: $orderid

    If you received this email, your mail function is working correctly.

    Regards,
    Your Website
    ";

    $headers = "From: no-reply@" . $_SERVER['SERVER_NAME'] . "\r\n";
    $headers .= "Reply-To: no-reply@" . $_SERVER['SERVER_NAME'] . "\r\n";
    $headers .= "Content-Type: text/plain; charset=UTF-8\r\n";

    if(mail($to, $subject, $body, $headers)) {
        $message = "✅ Email sent successfully to $to";
    } else {
        $message = "❌ Email failed to send. Check your server mail configuration.";
    }
}
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Mail Test</title>
<style>
body { font-family: Arial; max-width: 600px; margin: 50px auto; padding: 20px; background: #f4f4f4; }
.box { background: white; padding: 30px; border-radius: 8px; box-shadow: 0 0 10px rgba(0,0,0,0.1); }
input[type="email"], input[type="text"] { width: 100%; padding: 10px; margin: 10px 0; border: 1px solid #ddd; border-radius: 4px; }
input[type="submit"] { background: #28a745; color: white; padding: 12px 20px; border: none; border-radius: 4px; cursor: pointer; }
input[type="submit"]:hover { background: #218838; }
.info { margin-top: 20px; padding: 15px; border-radius: 4px; }
.success { background: #d4edda; border: 1px solid #c3e6cb; color: #155724; }
.error { background: #f8d7da; border: 1px solid #f5c6cb; color: #721c24; }
</style>
</head>
<body>

<div class="box">
<h2>Mail Test</h2>
<p>Enter your email to test server mail function.</p>

<form method="post">
<input type="email" name="email" placeholder="Your email for test" required>
<input type="text" name="orderid" placeholder="REPORT-ID (optional)">
<input type="submit" name="send" value="Send Test">
</form>

<?php if(!empty($message)): ?>
<div class="info <?php echo (strpos($message, 'successfully') !== false) ? 'success' : 'error'; ?>">
<?php echo $message; ?>
</div>
<?php endif; ?>

</div>

</body>
</html>