2016-12-07 11 views
0

まずはお手数ですが、 あなたが問題を見ることができるように、私は、テストページをアップロード:http://senoranabogados.com.ar/test1.htmlメールを送信中にGoogleのreCAPTCHAエラーが発生しました

そして、これは私が使用しているPHPのコードです:

<?php 

require_once('phpmailer/PHPMailerAutoload.php'); 

$toemails = array(); 

$toemails[] = array(
       'email' => 'Your email', // Your Email Address 
       'name' => 'Your Name' // Your Name 
      ); 

// Form Processing Messages 
$message_success = 'We have <strong>successfully</strong> received your Message and will get Back to you as soon as possible.'; 

// Add this only if you use reCaptcha with your Contact Forms 
$recaptcha_secret = 'your-recaptcha-secret-key'; // Your reCaptcha Secret 

$mail = new PHPMailer(); 

// If you intend you use SMTP, add your SMTP Code after this Line 


if($_SERVER['REQUEST_METHOD'] == 'POST') { 
    if($_POST['template-contactform-email'] != '') { 

     $name = isset($_POST['template-contactform-name']) ? $_POST['template-contactform-name'] : ''; 
     $email = isset($_POST['template-contactform-email']) ? $_POST['template-contactform-email'] : ''; 
     $phone = isset($_POST['template-contactform-phone']) ? $_POST['template-contactform-phone'] : ''; 
     $service = isset($_POST['template-contactform-service']) ? $_POST['template-contactform-service'] : ''; 
     $subject = isset($_POST['template-contactform-subject']) ? $_POST['template-contactform-subject'] : ''; 
     $message = isset($_POST['template-contactform-message']) ? $_POST['template-contactform-message'] : ''; 

     $subject = isset($subject) ? $subject : 'New Message From Contact Form'; 

     $botcheck = $_POST['template-contactform-botcheck']; 

     if($botcheck == '') { 

      $mail->SetFrom($email , $name); 
      $mail->AddReplyTo($email , $name); 
      foreach($toemails as $toemail) { 
       $mail->AddAddress($toemail['email'] , $toemail['name']); 
      } 
      $mail->Subject = $subject; 

      $name = isset($name) ? "Name: $name<br><br>" : ''; 
      $email = isset($email) ? "Email: $email<br><br>" : ''; 
      $phone = isset($phone) ? "Phone: $phone<br><br>" : ''; 
      $service = isset($service) ? "Service: $service<br><br>" : ''; 
      $message = isset($message) ? "Message: $message<br><br>" : ''; 

      $referrer = $_SERVER['HTTP_REFERER'] ? '<br><br><br>This Form was submitted from: ' . $_SERVER['HTTP_REFERER'] : ''; 

      $body = "$name $email $phone $service $message $referrer"; 

      // Runs only when File Field is present in the Contact Form 
      if (isset($_FILES['template-contactform-file']) && $_FILES['template-contactform-file']['error'] == UPLOAD_ERR_OK) { 
       $mail->IsHTML(true); 
       $mail->AddAttachment($_FILES['template-contactform-file']['tmp_name'], $_FILES['template-contactform-file']['name']); 
      } 

      // Runs only when reCaptcha is present in the Contact Form 
      if(isset($_POST['g-recaptcha-response'])) { 
       $recaptcha_response = $_POST['g-recaptcha-response']; 
       $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=" . $recaptcha_secret . "&response=" . $recaptcha_response); 

       $g_response = json_decode($response); 

       if ($g_response->success !== true) { 
        echo '{ "alert": "error", "message": "Captcha not Validated! Please Try Again." }'; 
        die; 
       } 
      } 

      $mail->MsgHTML($body); 
      $sendEmail = $mail->Send(); 

      if($sendEmail == true): 
       echo '{ "alert": "success", "message": "' . $message_success . '" }'; 
      else: 
       echo '{ "alert": "error", "message": "Email <strong>could not</strong> be sent due to some Unexpected Error. Please Try Again later.<br /><br /><strong>Reason:</strong><br />' . $mail->ErrorInfo . '" }'; 
      endif; 
     } else { 
      echo '{ "alert": "error", "message": "Bot <strong>Detected</strong>.! Clean yourself Botster.!" }'; 
     } 
    } else { 
     echo '{ "alert": "error", "message": "Please <strong>Fill up</strong> all the Fields and Try Again." }'; 
    } 
} else { 
    echo '{ "alert": "error", "message": "An <strong>unexpected error</strong> occured. Please Try Again later." }'; 
} 

?> 

私はhtmlページのフォームからのreCAPTCHAを削除するとメールが取得正しく送信されますが、recaptchaで「Bot Detected ...」というエラーメッセージが表示されます APIキーが正常であることを確認しました。

は、その後、私は別のPHPを使用しますが、ここではテストページを見ることができますsnipet:http://senoranabogados.com.ar/test2.html

これは、PHPのコードです:ここで

<?php 

     $email;$comment;$captcha; 
     if(isset($_POST['email'])){ 
      $email=$_POST['email']; 
     }if(isset($_POST['comment'])){ 
      $email=$_POST['comment']; 
     }if(isset($_POST['g-recaptcha-response'])){ 
      $captcha=$_POST['g-recaptcha-response']; 
     } 
     if(!$captcha){ 
      echo '<h2>Please check the the captcha form.</h2>'; 
      exit; 
     } 
    $secretKey = "your-recaptcha-secret-key"; 
    $ip = $_SERVER['REMOTE_ADDR']; 
     $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip); 
    $responseKeys = json_decode($response,true); 
     if(intval($responseKeys["success"]) !== 1) { 
      echo '<h2>You are spammer ! Get the @$%K out</h2>'; 
     } else { 
      echo '<h2>Thanks for posting comment.</h2>'; 
     } 
?> 

私は「AAを取得して暗号化を有効に失敗しました... "エラー

私が何を試みても、私はrecaptchaを動作させることはできません。

ご意見をいただければ幸いです。

+0

http://stackoverflow.com/questions/26148701/file-get-contents-ssl-operation-failed-with-code-1-and-more –

+0

私はこの問題を一時的に解決しましたが、このコードはPHP5.6で動作しません.5.5に切り替えて、今は正常に動作します。なぜか分からない。 – Julittok

答えて

0

私のコードはPHP 5.6と互換性がないようですので、私のサーバ上で5.5に変更しました。これが将来誰にでも役立つことを願っています。

関連する問題