How do you implement reCaptcha in php/html?

Wednesday, November 4, 2015

I'm having this problem where reCaptcha is not validating and not running my php code. I have one php file, and one html.
The code is supposed to send an email if the reCaptcha is validated, but ends up doing nothing and freezes on a blank screen on my webpage when i hit submit.



html cut-out:





<form onsubmit="" action="../structure/process_email.php" method="POST">


















</form>




reCaptcha script is placed in header:



https://www.google.com/recaptcha/api.js


php cut-out:





<?php 
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: xxx <xxx@xx.xx.xx>\r\n";

if(isset($_POST['submit'])) {
require_once('../structure/recaptchalib.php');
$privatekey = "xxxxxxxxxxxxxx";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);

if ($resp->is_valid) {
$email_to = 'xxx@xx.xx.xx';
$email_subject = 'New message: BMS - Contact us';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$content = "From:"." ".$name."\n"."Email:"." ".$email."\n\n".$message;
mail($email_to, $email_subject, $content, $headers);
header('location:../index.html');
} else {
}
header('location:../contact_us/contact_us.html');
}
?>





I have tried many different approaches on this problem, and i can't seem to find any solution. Have i forgot to write some code somewhere?

0 comments:

Post a Comment