Skip to content

Commit

Permalink
Disable form mail if spambot fills hidden field
Browse files Browse the repository at this point in the history
  • Loading branch information
hotwebmatter committed Nov 26, 2019
1 parent ff47a90 commit d858398
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions mail/contact_me.php
Expand Up @@ -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;
?>

0 comments on commit d858398

Please sign in to comment.