2015-10-26 55 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'] 
     ^--------------------^ 

代替。注意引號。