0

Using new Google reCAPTCHA Api with PHP

Using new Google reCAPTCHA Api with PHP

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

After getting the api keys now you need to include reCAPTCHA API JavaScript library.

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

Name: “.$name.”

Email: “.$email.”

Message: “.$message.”

“; // 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; ?>

Sandeep Kumar

Sandeep kumar is a web developer and a professinal blogger. He works for latest technologies and write articles what he learn. In ICodeHub he share web languages tutorials and other programming tips and tricks. if you need some help or have some suggestion then mail him at sandeep92pal@gmail.com without any hesitation. He believes in learning and sharing.