Using new Google reCAPTCHA Api with PHP
reCAPTCHA is the best way, so users can prove they are human without solving a CAPTCHA. reCAPTCHA will protect your website from spam form entries. Todays i am going to share, how you can use the google reCAPTCHA Api with PHP scripting language. In following php script i am creating a simple form in which i am using reCAPTCHA.
Step 1 Get reCAPTCHA API keys:
Using google reCAPTCHA api in you website, you must need to add your website in google to get the reCAPTCHA API Keys and screat keys
Register your site
Register your site at Google from here – https://www.google.com/recaptcha/admin
Step 2 Html Code
<script src="https://www.google.com/recaptcha/api.js" async="" defer="defer"></script>
Before the Submit button we have placed the Google reCAPTCHA widget div. Modify the data-sitekey attribute value with your Site Key.
Step 3 PHP Code
Contact request details
“; // Always set content-type when sending HTML email $headers = “MIME-Version: 1.0” . “\r\n”; $headers .= “Content-type:text/html;charset=UTF-8” . “\r\n”; // More headers $headers .= ‘From:’.$name.’ <‘.$email.’>’ . “\r\n”; //send email @mail($to,$subject,$htmlContent,$headers); $succMsg = ‘Your contact request have submitted successfully.’; else: $errMsg = ‘Robot verification failed, please try again.’; endif; else: $errMsg = ‘Please click on the reCAPTCHA box.’; endif; else: $errMsg = ”; $succMsg = ”; endif; ?>