How do I remove g-recaptcha-response in an online form?
See below the image I have highlighted. May I know how to remove g-recaptcha-response when I receive the email?
$mailTo = "$email_address";
$mailSubject = "$email_subject";
$mailBody = "The form values entered by the user are as follows: \n\n";
foreach($HTTP_POST_VARS as $key=>$value)
{
if(isset($_POST['g-recaptcha-response'])){$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha)
{
echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$redirect_to_failed\">";
exit;
}
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
if($response.success==false)
{
echo '<h2>You are spammer! /h2>';
}else
{
echo '<h2>Thanks for contacting us.</h2>';
}
$mailBody .= "$key = $value\n";
}
+3
source to share
1 answer
Check g-recaptcha-response
outside of the loop, there is no need to check it every time you iterate.
Then check that the variable key is $_POST
not g-recaptcha-response
before adding it to the message.
$mailTo = "$email_address";
$mailSubject = "$email_subject";
$mailBody = "The form values entered by the user are as follows: \n\n";
if(isset($_POST['g-recaptcha-response'])){$captcha=$_POST['g-recaptcha-response'];
}
foreach($HTTP_POST_VARS as $key=>$value)
{
if(!$captcha)
{
echo "<meta HTTP-EQUIV=\"REFRESH\" content=\"0; url=$redirect_to_failed\">";
exit;
}
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
if($response.success==false)
{
echo '<h2>You are spammer! /h2>';
}else
{
echo '<h2>Thanks for contacting us.</h2>';
}
if ($key != 'g-recaptcha-response') {
$mailBody .= "$key = $value\n";
}
}
+4
source to share