Disable form mail if spambot fills hidden field

This commit is contained in:
Matthew Obert 2019-11-26 09:36:53 -05:00 committed by GitHub
parent ff47a9045c
commit d85839854a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 9 deletions

View File

@ -20,7 +20,7 @@ if ($email_address === FALSE) {
$phone = $_POST['phone']; $phone = $_POST['phone'];
$message = $_POST['message']; $message = $_POST['message'];
if (empty($_POST['_gotcha'])) { // If hidden field was filled out (by spambots) don't send!
// Create the email and send the 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. $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_subject = "Website Contact Form: $name";
@ -29,4 +29,7 @@ $headers = "From: noreply@yourdomain.com\n"; // This is the email address the ge
$headers .= "Reply-To: $email_address"; $headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers); mail($to,$email_subject,$email_body,$headers);
return true; return true;
}
echo "Gotcha, spambot!";
return false;
?> ?>