php - 未定义的索引: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);
解决方案
推荐阅读
- google-sheets - 使用多个 SUBSTITUTE 简化公式以获得相同的最终值
- arrays - 使用以数组为值的过滤器查询json
- go - ffmpeg:读取标头管道时出错:0:参数无效
- neo4j - 尝试从 Neo4j Cypher 查询中获取与唯一端点的关系
- java - HashMap以小数形式打印字母频率?
- javascript - 如何通过fabricjs在矩形形状上显示尺寸?
- sas - 这段代码不起作用有什么特别的原因吗?
- python - 为什么我的 MiniMax 实施不起作用?
- python-3.x - 首先,IntervalIndex 中的最后一个 bin
- bash - Bash ls 命令在 shell 脚本中不起作用