Get Website Lowest price!

Wordpress Experts!

×

php up to date

How to integrate Google Captcha in the contact form using PHP using Version 2.0

How to integrate Google Captcha in the contact form using PHP


  Here I can show you how to include google captcha version 2.0 integration in the contact form. 
Step 1:
                Create captcha Account using https://www.google.com/recaptcha this link
Step 2 :
               Register your Website address that mean website url.
Step 3:
                Once you entered your website URL you will get secret key

URL: https://www.google.com/recaptcha/api/siteverify
secret (required)6LdHGIYUAAAAADA67iyHZfcXvIvIBpWMZx0MBRfE
response (required)The value of 'g-recaptcha-response'.
remoteipThe end user's ip address.
This is the overall concept to integrate code in your website, Here i can give you full code to send mail.email,
<?php
header('Content-type: application/json'); $status = array( 'type'=>'success', 'message'=>'Thank you for contact us. We will get touch with you within 2 days ' );
// More headers$headers .= 'From: <info@sssss.com>' . "\r\n";$headers .= 'Cc: sssss@gmail.com' . "\r\n";
    $name = @trim(stripslashes($_POST['name']));     $email = @trim(stripslashes($_POST['email']));     $subject = @trim(stripslashes($_POST['subject']));     $message = @trim(stripslashes($_POST['message']));     $phone = @trim(stripslashes($_POST['phone']));     $company = @trim(stripslashes($_POST['company']));     $service = @trim(stripslashes($_POST['service'])); ;    $email_from = 'info@eightlegbuilders.com';    $email_to = 'ssss@gmail.com';//replace with your email    $email_to = ''; if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response']))             {                         if (strstr($_POST['email'], $hn))        {                              $secret = 'secretkey';                  $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']);        $responseData = json_decode($verifyResponse); if(responseData==='success') { $allowed_hostnames = array("gmail.com", "yahoo.com");    $good_hostname = false;    foreach ($allowed_hostnames as $hn)    {        if (strstr($_POST['email'], $hn))        {            $body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Contact Number:' . $phone ."\n\n" . 'Company Name:' . $company ."\n\n". 'Message: ' . $message."\n\n". 'Job Required: ' .$service;
    $success = mail($email_to, $subject, $body, $headers);
    echo json_encode($status);    die;        }else{            if ($good_hostname==false)            {                // Keepin' it false here!                $good_hostname = false; // Set it to false anyway            }        }    } }}}    
?>









































SHARE

Unknown

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment