From 92812bc70cb525135e97033f9332994fec34e794 Mon Sep 17 00:00:00 2001 From: Chneemann Date: Sat, 25 Jul 2026 08:07:04 +0200 Subject: [PATCH] feat: integrate form state and sendMail endpoint fetch --- sendMail.php | 37 +++++++++++++++++++ src/components/Contact.tsx | 73 ++++++++++++++++++++++++++++++-------- 2 files changed, 96 insertions(+), 14 deletions(-) create mode 100644 sendMail.php diff --git a/sendMail.php b/sendMail.php new file mode 100644 index 0000000..440e699 --- /dev/null +++ b/sendMail.php @@ -0,0 +1,37 @@ +email; + $name = $params->name; + $message = $params->message; + + $recipient = 'dev@andre-kempf.com'; + $subject = "Contact Form <$email>"; + $message = "From: $name
Email: $email

$message"; + + $headers = array(); + $headers[] = 'MIME-Version: 1.0'; + $headers[] = 'Content-type: text/html; charset=utf-8'; + $headers[] = "From: noreply@andre-kempf.com"; + + mail($recipient, $subject, $message, implode("\r\n", $headers)); + break; + + default: // Reject non-POST or OPTIONS requests. + header("Allow: POST", true, 405); + exit; +} \ No newline at end of file diff --git a/src/components/Contact.tsx b/src/components/Contact.tsx index df86b55..effd8b1 100644 --- a/src/components/Contact.tsx +++ b/src/components/Contact.tsx @@ -3,13 +3,43 @@ import { useState } from "react"; export default function Contact() { - // Placeholder - const [submitted, setSubmitted] = useState(false); + const [name, setName] = useState(""); + const [email, setEmail] = useState(""); + const [message, setMessage] = useState(""); - const handleSubmit = (e: React.SubmitEvent) => { + const [submitted, setSubmitted] = useState(false); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(false); + + const handleSubmit = async (e: React.SubmitEvent) => { e.preventDefault(); - // Mailer / Formspree / API Call integration goes here - setSubmitted(true); + + setLoading(true); + setError(false); + + try { + const response = await fetch("https://andre-kempf.com/sendMail.php", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ name, email, message }), + }); + + if (response.ok) { + setSubmitted(true); + setName(""); + setEmail(""); + setMessage(""); + } else { + setError(true); + } + } catch (err) { + console.error("Mail send error:", err); + setError(true); + } finally { + setLoading(false); + } }; return ( @@ -93,44 +123,59 @@ export default function Contact() { ) : (
- + setName(e.target.value)} placeholder="John Doe" - className="w-full px-4 py-2.5 rounded-xl bg-slate-950/60 border border-slate-800 text-white placeholder:text-slate-600 focus:outline-none focus:border-blue-500/80 focus:ring-1 focus:ring-blue-500/80 transition-colors text-sm" + className="w-full px-4 py-2.5 rounded-xl bg-slate-950/60 border border-slate-800 text-slate-100 placeholder:text-slate-600 focus:outline-none focus:border-blue-500/80 focus:ring-1 focus:ring-blue-500/80 transition-colors text-sm" />
-
-