From 3afa0a47415a632758333d2935b806324a3b651b Mon Sep 17 00:00:00 2001 From: hugo Date: Sun, 9 Jun 2024 10:40:37 +0200 Subject: [PATCH] MAJ du portfolio --- PHP/main.php | 12 +++++++----- index.html | 18 +++++++++--------- js/script.js | 25 +++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 14 deletions(-) diff --git a/PHP/main.php b/PHP/main.php index 00cbb29..ba17083 100644 --- a/PHP/main.php +++ b/PHP/main.php @@ -11,13 +11,15 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { $email_body = "You have received a new message from $name ($email):\n\n$message"; - $headers = "From: $name <$email>\r\n"; + $from = "hugo.crneau@gmail.com"; + + $headers = "From: $from\r\n"; $headers .= "Reply-To: $email\r\n"; if (mail($to, $email_subject, $email_body, $headers)) { - header("Location: index.html"); - exit; + echo "success"; } else { - echo "Failed to send the email."; + echo "error"; } -} \ No newline at end of file +} +?> diff --git a/index.html b/index.html index 6e1ec54..eb1cb72 100644 --- a/index.html +++ b/index.html @@ -746,34 +746,34 @@ me contacter au mail ci dessus)

JE REPONDS AUX MESSAGES

-
+
- - + +
- - + +
- - + +
- - + +
diff --git a/js/script.js b/js/script.js index e95a5b5..51e9bc4 100644 --- a/js/script.js +++ b/js/script.js @@ -123,3 +123,28 @@ portfolioImages.forEach(function (image, index) { } }); }); + +document + .getElementById("contactForm") + .addEventListener("submit", function (event) { + event.preventDefault(); + + var formData = new FormData(this); + + var xhr = new XMLHttpRequest(); + xhr.open("POST", "/PHP/main.php", true); + + xhr.onload = function () { + if (xhr.status === 200) { + if (xhr.responseText === "success") { + alert("Email envoyé avec succès!"); + } else { + alert("Échec de l'envoi de l'email."); + } + } else { + alert("Une erreur s'est produite. Veuillez réessayer."); + } + }; + + xhr.send(formData); + });