2016-07-26 21 views
2
<?php 
if(isset($_POST['submit'])) 
{ 
$email=$_POST['email']; 
$comment=$_POST['comment']; 
$captcha=$_POST['g-recaptcha-response']; 
if(!$captcha) 
{ 
    echo 'Please check the the captcha form.'; 
} 

$response=file_get_contents("https://www.google.com/recaptcha/api/sitev erify?secret="secretkey"  &response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']); 

if($response.success==false) 
{ 
    header('Location:http://mywebsite.com/.errordocs/404.html'); 
} 
else 
{ 
    header('Location:http://mywebsite.com/thankyou.php'); 
} 
} 

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

$name = $_POST['name']; 

$last = $_POST['last']; 

$email = $_POST['email']; 

$phone = $_POST['phone']; 

$comments = $_POST['comments']; 
// Build the email (replace the address in the $to section with Enjoy's contact e-mail) 

$to = '[email protected]'; 

$subject = "Main Contact Form"; 

$message = "Name: $name 

Email: $email 

Phone: $phone 

Comments: $comments"; 

$headers = "From: $email \r\n"; 

mail($to, $subject, $message, $headers); 
} 
?> 

問題是何時在窗體上驗證了驗證碼,它顯示覆選標記,用戶可以單擊提交,但我得到一個空白屏幕和電子郵件不發送。任何幫助非常感謝,已經爲此工作了大約3周。在php中驗證後不會收發電子郵件

+2

因爲你從頁面重定向走之前打個電話發送的電子郵件 – 2016-07-26 03:53:17

回答

1

實際發送電子郵件之前,您當前正在重定向。這裏是你的代碼重組。也是固定的ReCaptcha響應處理

<?php 
if (isset($_POST['submit'])){ 
    $email = $_POST['email']; 
    $comment = $_POST['comment']; 
    $captcha = $_POST['g-recaptcha-response']; 
    if (! $captcha){ 
     echo 'Please check the the captcha form.'; 
     exit(); 
    }else{ 

     $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $secretkey . "&response=" . $captcha . "&remoteip=" . $_SERVER['REMOTE_ADDR']); 

     $responseKeys = json_decode($response,true); 
     if (intval($responseKeys["success"]) !== 1){ 
      header('Location:http://mywebsite.com/.errordocs/404.html'); 
      exit(); 
     }else{ 


      if (isset($_POST['Side_Form'])){//not sure what this is, hopefully you do :-) 

       $name = $_POST['name']; 

       $last = $_POST['last']; 

       $email = $_POST['email']; 

       $phone = $_POST['phone']; 

       $comments = $_POST['comments']; 
       // Build the email (replace the address in the $to section with Enjoy's contact e-mail) 

       $to = '[email protected]'; 

       $subject = "Main Contact Form"; 

       $message = "Name: $name 
Email: $email 
Phone: $phone 
Comments: $comments"; 

       $headers = "From: $email \r\n"; 

       mail($to,$subject,$message,$headers); 
       header('Location:http://mywebsite.com/thankyou.php'); 
       exit(); 
      } 
     } 
    } 
} 
?> 
+0

嘿,非常感謝您的幫助!我粘貼提供的代碼,但現在我得到這個錯誤: 解析錯誤:語法錯誤,意外'6'(T_LNUMBER) –