Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: Google Recaptcha integration

Ollie Vincent pro asked 7 years ago


Hi, I am trying to integrate the Google Recaptcha service into my bootstrap form. I have successfully got it on the site - with the data sitekey, however I have no where to put my secret key. I believe I am missing some PHP code, but all Google says is "write a POST command". This doesn't really help me. Does anyone have any code that may work? Thanks

Bartłomiej Malanowski staff commented 7 years ago

Share your PHP code with us

Ollie Vincent pro answered 7 years ago


My PHP code is as follows... Thanks

?php
if(isset( $_POST['name']))

$name = $_POST['name'];
if(isset( $_POST['email']))
$email = $_POST['email'];
if(isset( $_POST['phone']))
$phone = $_POST['phone'];
if(isset( $_POST['company']))
$company = $_POST['company'];
if(isset( $_POST['message']))
$message = $_POST['message'];
if(isset( $_POST['subject']))
$subject = $_POST['subject'];
if ($name === ''){
echo "Please enter your name";
die();
}
if ($email === ''){
echo "Please enter your email";
die();
} else {
if (!filter_var($email, FILTER_VALIDATE_EMAIL)){
echo "Please check your email";
die();
}
}

if ($subject === ''){
echo "Please type the subject of your message";
die();
}
if ($message === ''){
echo "Please enter your message";
die();
}

if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}

if(!$captcha){
echo 'Please check the the captcha form.';
exit;
}
$secretKey = "my secret key";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
echo '
} else {

echo '

 

$content="From: $name n Email: $email n Phone: $phone n Company: $company n Subject: $subject n Message: $message";
$recipient = "my email";
$mailheader = "From: $email rn";
mail($recipient, $subject, $content, $mailheader) or die("Error!");

echo "Thanks for emailing me. I will try to get back to you as soon as possible. In the meantime, why not look around? ";

 



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: Other
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No
Tags