Reputation: 1
Im using Google Recaptcha, and I've ended up with this piece of code. My goal is to have my already working php form to submit only when the captcha has been completed. Any help would be appreciated.
<?php
if (isset($_POST['ContactButton'])) {
$url = 'https://www.google.com/recaptcha/api/siteverify';
$privatekey = "6LePayETAAAAANJze7opnV6bQEX-n02p4UdZ8xfF";
$response = file_get_contents($url . "?
secret=" . $privatekey . "&response" . $_POST['g-recaptcha-
response'] . "&remoteip=" . $_SERVER['REMOTE_ADDR']);
$data = json_decode($respose);
if (isset($data -> success) AND $data -> success == true) {
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent = " From: $name \n Phone: $phone \n Message: $message";
$recipient = "[email protected]";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header('Location: contact-thank-you.html');
exit();
} else {
header('location: index.html?captchafail=True');
}
}
?>
Upvotes: 0
Views: 288
Reputation: 757
Have you tried using honeytrap instead of captcha which is more simple and does the same functionality http://blog.mtstudios.net/the-honey-trap-the-easiest-way-ive-found-to-stop-spam-emails-on-asp-net-contact-forms/
Upvotes: 1
Reputation: 556
Please read the google's developer documentation for reCAPTCHA and github page that will help you
Upvotes: 0