2016-04-27 45 views
-2

太多的嘗試後reCapatcha添加到我的聯繫表格 我想幫助 這是我的聯繫方式的PHP代碼:如何添加谷歌的reCAPTCHA在此代碼

<? 
$name = $_POST[name]; 
$email = $_POST[email]; 
$type = $_POST[type]; 
$message = $_POST[message]; 

if ($name == "") { 
    die('name null'); 
} 
if ($type == "" || $email == "" || $message == "") { 
    die("not null"); 
} 

$myemail = "[email protected]"; 
$s = "$name"; 
$body = "<b>Message from Client</b> <br><br> Name: <b>$name</b><br> Package: <b>$type</b><br> E-mail: <b>$email</b><br> Message: <b>$message</b>"; 

$headers = 'From: '.$email."\r\n".'Content-Type: text/html; charset=utf-8'."\r\n"; 

mail($myemail, $s, $body, $headers); 

header('Content-Type: application/json'); 
echo json_encode(array('response' => 'success')); 
?> 

請我怎麼可以在這裏添加的ReCaptcha?!

+0

不要只說你已經嘗試過,請告訴我們你的工作。我們會很樂意幫助您試用您的產品,而不是期望我們爲您修改額外功能的代碼。 –

+0

你在開玩笑嗎?這是你的聯繫方式嗎? ?我無法看到任何文本框 –

+0

@NanaPartykar這是php聯繫人文件:) –

回答

0

Ameeer Assadi,

也許這樣的事?

<?php 
if(isset($_POST['submit']) && !empty($_POST['submit'])): 
    if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])): 

     $secret = ''; //enter your key between '' 


     $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): 


      $name = !empty($_POST['name'])?$_POST['name']:''; 
      $email = !empty($_POST['email'])?$_POST['email']:''; 
      $message = !empty($_POST['message'])?$_POST['message']:''; 

      $to = '[email protected]'; 
      $subject = 'New contact form have been submitted'; 
      $htmlContent = " 
       <h1>Contact request details</h1> 
       <p><b>Name: </b>".$name."</p> 
       <p><b>Email: </b>".$email."</p> 
       <p><b>Message: </b>".$message."</p> 
      "; 

      $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; 
?> 
+0

我試過這不是工作 –

+0

你得到什麼錯誤?... –

+0

錯誤!發送您的消息時發生錯誤。 –