<?php

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $nom = htmlspecialchars($_POST['nom']);

    $prenom = htmlspecialchars($_POST['prenom']);

    $email = htmlspecialchars($_POST['email']);

   

    $to = "ilyass.abouali9@gmail.com";

    $subject = "Nouveau message du formulaire de contact";

    $message = "Nom: " . $nom . "n" .

               "Prénom: " . $prenom . "n" .

               "Email: " . $email;

   

    $headers = "From: " . $email . "rn" .

               "Reply-To: " . $email . "rn" .

               "X-Mailer: PHP/" . phpversion();

 

    if(mail($to, $subject, $message, $headers)) {

        echo "<script>

                alert('Message envoyé avec succès!');

                window.location.href = 'index.html';

              </script>";

    } else {

        echo "<script>

                alert('Erreur lors de l'envoi du message.');

                window.location.href = 'index.html';

              </script>";

    }

}

?>