Form Value not getting back to my email <google captcha working fine>

Hi Experts…

I am working on this beautiful sunday night :frowning: Please help

After wasting whole 2 days with fiveer php person,
i (Graphics Designer, Not a coder) somehow understood by forums and youtube videos and
enabled google recaptcha for my email form,
now captcha work fine, but i am unable to get filled value in my email back from the form.
[php]

<?php if(isset($_POST['submit'])): if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])): //your site secret key $secret = 'mygooglescretkey'; //get verify response data $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']); $responseData = json_decode($verifyResponse); $name = !empty($_POST['name'])?$_POST['name']:''; $email = !empty($_POST['email'])?$_POST['email']:''; $message = !empty($_POST['message'])?$_POST['message']:''; if($responseData->success): //contact form submission code $to = "info@mydomain,com, [email protected]"; $subject = 'Naming Form via Website'; $email_from = 'info@mydomain,com'; //!-- >mail($mailto,$subject,$message_body,"From:".$from); $htmlContent = "

Contact request details

Name: ".$name."

Email: ".$email."

Message: ".$message."

"; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $headers .= 'From:'.$name.' <'.$email.'>' . "\r\n"; //send email mail($to,$subject,$html_Content,$headers,"From:".$email_from); $succMsg = 'Your contact request have submitted successfully.'; $name = ''; $email = ''; $message = ''; $to = ''; $from = ''; $headers = ''; header('Location: http://www.mydomain.com/thankyou.htm'); else: $errMsg = 'Robot verification failed, please try again.'; endif; else: $errMsg = 'Please click on the reCAPTCHA box.'; endif; else: $errMsg = ''; $succMsg = ''; $name = ''; $email = ''; $message = ''; $to = ''; $from = ''; $headers = ''; endif; ?>

[/php]

[php]

Using new Google reCAPTCHA with PHP by CodexWorld




Contact Form

<?php if(!empty($errMsg)): ?>
<?php echo $errMsg; ?>
<?php endif; ?> <?php if(!empty($succMsg)): ?>
<?php echo $succMsg; ?>
<?php endif; ?>
<?php echo !empty($message)?$message:''; ?>
[/php]

Sorry I didn’t read you question correctly, but are you sure you implemented it correctly? Also when I had to do the final testing I had to check it on the remote server and not my local server (I also mention this at the bottom of my response).
You need to do something like this:

[php]if (isset($submit) && $submit === ‘submit’) {
/* The Following to get response back from Google recaptcah */
$url = “https://www.google.com/recaptcha/api/siteverify”;

$remoteServer = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_SANITIZE_URL);
$response = file_get_contents($url . "?secret=" . PRIVATE_KEY . "&response=" . \htmlspecialchars($_POST['g-recaptcha-response']) . "&remoteip=" . $remoteServer);
$recaptcha_data = json_decode($response);
 /* The actual check of the recaptcha */
if (isset($recaptcha_data->success) && $recaptcha_data->success === TRUE) {
    $first_name = filter_input(INPUT_POST, 'first_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
    $last_name = filter_input(INPUT_POST, 'last_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
    $name = $first_name . ' ' . $last_name;
    $email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
    $message = filter_input(INPUT_POST, 'comment', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
    $topic = filter_input(INPUT_POST, 'reason', FILTER_SANITIZE_SPECIAL_CHARS);

    /* Spambot check this uses a hidden Captcha technique */
    $spambot = filter_input(INPUT_POST, 'subject', FILTER_SANITIZE_SPECIAL_CHARS);


    $send = new SendForm(new Email($name, $email, $topic, $message, $spambot));
    if (!$send->sendMail()) {
        if (!$send->getName()) {
            $nameError = $send->getNameError();
        } else {
            $displayName = $send->getName();
        }

        if (!$send->getEmail()) {

            $emailError = $send->getEmailError();
        } else {
            $displayEmail = $send->getEmail();
        }
        if (!$send->getMessage()) {
            $messageError = $send->getMessageError();
        } else {
            $displayMessage = $send->getMessage();
        }
    } else {
        $success = 'Email successfully sent!';  // Set the success message if message was sent correctly:
    }
} else {
    $success = "You're not a human!";
}

}[/php]

I would also go to Google itself for they have a nice “How to implement” on Captcha. You can somewhat test it out on a local server ( final testing will be done on the remote server) and once again Google will show you on how to do it.

if (isset($submit) && $submit === 'submit') {

No, no, no! Not now, not ever

[php]if ($_SERVER[‘REQUEST_METHOD’] == ‘POST’){

}[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service