<?php
$out = __DIR__ . '/../data/outbox.txt';
$ok = false;

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $msg = trim($_POST['msg'] ?? '');

    if ($msg !== '') {
        file_put_contents($out, $msg . PHP_EOL, FILE_APPEND);
        $ok = true;
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Send test</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
<div class="wrap">
    <div class="card">
        <h2>Send test-besked</h2>
        <p><a class="btn" href="index.php">← Tilbage</a></p>

        <?php if ($ok): ?>
            <p class="notice">Sendt til outbox.</p>
        <?php endif; ?>

        <form method="post">
            <label>
                Besked
                <input name="msg" placeholder="Hej chat!">
            </label>
            <br>
            <button class="btn">Send</button>
        </form>
    </div>
</div>
</body>
</html>
