2015-10-26 23 views
0

我有一些麻烦设置recaptha与我有限的PHP知识。我设法从根本上解决了这个问题,但是我发现知道我的表单数据没有提交。PHP表格数据没有提交与recaptcha

这里是PHP,因为它主张:

<?php 
$sendToEmail="[email protected]";  

$yourname = $_POST["yourname"]; 
$timecall = $_POST["timecall"]; 
$email=$_POST["email"]; 
$phone=$_POST["phone"]; 
$message=$_POST["message"];  


$content = "Time to Call : " . $timecall . "<br>"; 
$content .= "Name : " . $yourname . "<br>"; 
$content .= "Email : " . $email . "<br>"; 
$content .= "Phone : " . $phone . "<br>"; 
$content .= "Message : ". $message ."<br>";  


$senderEmailId = "Reply-To: $email"; 
$senderEmailId = "From: $email\r\n"; 
$senderEmailId .= "Content-type: text/html\r\n"; 
$subject ="New Enquiry from the website";  

    if(isset($_POST['ContactButton'])) {  

      $url = 'https://www.google.com/recaptcha/api/siteverify'; 
      $privatekey = "--private-key--";  

      $response = file_get_contents($url."?secret=".$privatekey."&response=".$_POST[g-recaptcha-response]."&remoteip=".$_SERVER['REMOTE_ADDR']);  

     $data = json_decode($response);  

     if (isset($data->success) AND $data->success==true) {  

//// True- what happens when user is verified  

    header("Location:thankyou.php?CaptchaPass=True");  


     }else{  

    header("Location:thankyou.php?CaptchaFail=True"); 

     } 
} 
?>  

预先感谢您!

回答

1

PHP 101:未引用的数组键字符串被视为未定义的常量。您有:

$_POST[g-recaptcha-response] 

被解析/执行作为

$_POST[g minus recaptcha minus response] 
$_POST[0 minus 0 minus 0] 
$_POST[0] 

如果你有一个PHP的调试选项(error_reportingdisplay_errors),你会被给予这个警告。首先,这些设置不应该在调试/开发服务器上关闭。

尝试

$_POST['g-recaptcha-response'] 
     ^--------------------^ 

代替。注意引号。