diff --git a/sendMail.php b/sendMail.php index 440e699..57cb3d8 100644 --- a/sendMail.php +++ b/sendMail.php @@ -14,6 +14,12 @@ switch ($_SERVER['REQUEST_METHOD']) { $json = file_get_contents('php://input'); $params = json_decode($json); + // Honeypot check + if (!empty($params->website)) { + http_response_code(200); + exit; + } + // Extract values $email = $params->email; $name = $params->name; diff --git a/src/components/Contact.tsx b/src/components/Contact.tsx index effd8b1..7160259 100644 --- a/src/components/Contact.tsx +++ b/src/components/Contact.tsx @@ -6,14 +6,30 @@ export default function Contact() { const [name, setName] = useState(""); const [email, setEmail] = useState(""); const [message, setMessage] = useState(""); + const [honeypot, setHoneypot] = useState(""); const [submitted, setSubmitted] = useState(false); const [loading, setLoading] = useState(false); const [error, setError] = useState(false); + const [formLoadTime] = useState(Date.now()); + const handleSubmit = async (e: React.SubmitEvent) => { e.preventDefault(); + // Bot check + const timeTaken = (Date.now() - formLoadTime) / 1000; + + if (timeTaken < 3) { + setSubmitted(true); + return; + } + + if (honeypot !== "") { + setSubmitted(true); + return; + } + setLoading(true); setError(false); @@ -23,7 +39,7 @@ export default function Contact() { headers: { "Content-Type": "application/json", }, - body: JSON.stringify({ name, email, message }), + body: JSON.stringify({ name, email, message, honeypot }), }); if (response.ok) { @@ -31,6 +47,7 @@ export default function Contact() { setName(""); setEmail(""); setMessage(""); + setHoneypot(""); } else { setError(true); } @@ -122,6 +139,21 @@ export default function Contact() { ) : (
+ +