From d85839854a8e127b0a9acc415398eb52d852fd5f Mon Sep 17 00:00:00 2001 From: Matthew Obert Date: Tue, 26 Nov 2019 09:36:53 -0500 Subject: [PATCH] Disable form mail if spambot fills hidden field --- mail/contact_me.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mail/contact_me.php b/mail/contact_me.php index b231ed70b8..05170c0182 100755 --- a/mail/contact_me.php +++ b/mail/contact_me.php @@ -20,13 +20,16 @@ $phone = $_POST['phone']; $message = $_POST['message']; - -// Create the email and send the message -$to = 'yourname@yourdomain.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to. -$email_subject = "Website Contact Form: $name"; -$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message"; -$headers = "From: noreply@yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com. -$headers .= "Reply-To: $email_address"; -mail($to,$email_subject,$email_body,$headers); -return true; +if (empty($_POST['_gotcha'])) { // If hidden field was filled out (by spambots) don't send! + // Create the email and send the message + $to = 'yourname@yourdomain.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to. + $email_subject = "Website Contact Form: $name"; + $email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message"; + $headers = "From: noreply@yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com. + $headers .= "Reply-To: $email_address"; + mail($to,$email_subject,$email_body,$headers); + return true; +} +echo "Gotcha, spambot!"; +return false; ?>