I am trying to incorporate Google's ReCaptcha API with PHPMailer, however, I am being faced with 'Undefined index:' error. I am using 'if (isset($_POST['submit']))' so unsure of why this error is being produced.
error:
Undefined index: g-recaptcha-response in C:\xampp\htdocs\contact-form-ajax\contactForm.php on line 15
Please, could someone share some light on this and help with a solution?
I have only pasted in the first part of the code, however, if you require more I can add :)
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);