首页 > 解决方案 > 未定义的索引:g-recaptcha-response 与 PHPMailer

问题描述

我正在尝试将 Google 的 ReCaptcha API 与 PHPMailer 结合起来,但是,我遇到了“未定义的索引:”错误。我正在使用 'if (isset($_POST['submit']))' 所以不确定为什么会产生这个错误。

错误:

未定义索引:第 15 行 C:\xampp\htdocs\contact-form-ajax\contactForm.php 中的 g-recaptcha-response

拜托,有人可以分享一下这个问题并帮助解决吗?

我只粘贴了代码的第一部分,但是,如果您需要更多,我可以添加:)

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

  require 'dist/PHPMailer/PHPMailerAutoload.php';
  $mail = new PHPMailer;

  $name = $_POST['name'];
  $email = $_POST['email'];
  $subject = $_POST['subject'];
  $phone = $_POST['phone'];
  $company = $_POST['company'];
  $message = $_POST['message'];
  $secretKey = "--KEY--";
  $responseKey = $_POST['g-recaptcha-response'];
  $userIP = $_SERVER['REMOTE_ADDR'];

  $url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$userIP";
  $response = file_get_contents($url);

标签: phprecaptcha

解决方案


推荐阅读