reCaptcha Not Submitted

7 replies · opened Mar 7, 2018

BBlunt_HausMar 7, 2018

Hi Canvas Support,

My reCaptcha is unable to verify and send me the link.

a live example can be found at www.equitosgroup.com/contactus.html

Please help as I need to have the contact form and verification working.

I have already checked my server configuration is correct with allow_url_fopen enabled.

Please help!

<?php

use PHPMailer\PHPMailer\PHPMailer;

require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';

$toemails = array();

$toemails[] = array(
'email' => 'info@equitosgroup.com', // Your Email Address
'name' => 'Equitos Group' // Your Name
);

// Form Processing Messages
$message_success = 'We have successfully received your Message and will get Back to you as soon as possible.';

// Add this only if you use reCaptcha with your Contact Forms
$recaptcha_secret = '6LexD0UUAAAAAA5xp-TgneqD73JsxAlnh3Xcuc4f'; // Your reCaptcha Secret

$mail = new PHPMailer();

// If you intend you use SMTP, add your SMTP Code after this Line

if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
if( $_POST['template-contactform-email'] != '' ) {

    $name = isset( $_POST['template-contactform-name'] ) ? $_POST['template-contactform-name'] : '';
    $email = isset( $_POST['template-contactform-email'] ) ? $_POST['template-contactform-email'] : '';
    $phone = isset( $_POST['template-contactform-phone'] ) ? $_POST['template-contactform-phone'] : '';
    $service = isset( $_POST['template-contactform-service'] ) ? $_POST['template-contactform-service'] : '';
    $subject = isset( $_POST['template-contactform-subject'] ) ? $_POST['template-contactform-subject'] : '';
    $message = isset( $_POST['template-contactform-message'] ) ? $_POST['template-contactform-message'] : '';
    
    $subject = isset($subject) ? $subject : 'New Message From Contact Form';
    
    $botcheck = $_POST['template-contactform-botcheck'];
    
    if( $botcheck == '' ) {
        
        $mail-&gt;SetFrom( $email , $name );
        $mail-&gt;AddReplyTo( $email , $name );
        foreach( $toemails as $toemail ) {
            $mail-&gt;AddAddress( $toemail['email'] , $toemail['name'] );
        }
        $mail-&gt;Subject = $subject;
        
        $name = isset($name) ? "Name: $name&lt;br&gt;&lt;br&gt;" : '';
        $email = isset($email) ? "Email: $email&lt;br&gt;&lt;br&gt;" : '';
        $phone = isset($phone) ? "Phone: $phone&lt;br&gt;&lt;br&gt;" : '';
        $service = isset($service) ? "Service: $service&lt;br&gt;&lt;br&gt;" : '';
        $message = isset($message) ? "Message: $message&lt;br&gt;&lt;br&gt;" : '';
        
        $referrer = $_SERVER['HTTP_REFERER'] ? '&lt;br&gt;&lt;br&gt;&lt;br&gt;This Form was submitted from: ' . $_SERVER['HTTP_REFERER'] : '';
        
        $body = "$name $email $phone $service $message $referrer";
        
        // Runs only when File Field is present in the Contact Form
        if ( isset( $_FILES['template-contactform-file'] ) && $_FILES['template-contactform-file']['error'] == UPLOAD_ERR_OK ) {
            $mail-&gt;IsHTML(true);
            $mail-&gt;AddAttachment( $_FILES['template-contactform-file']['tmp_name'], $_FILES['template-contactform-file']['name'] );
        }
        
        // Runs only when reCaptcha is present in the Contact Form
        if( isset( $_POST['g-recaptcha-response'] ) ) {
            $recaptcha_response = $_POST['g-recaptcha-response'];
            $response = file_get_contents( "https://www.google.com/recaptcha/api/siteverify?secret=" . $recaptcha_secret . "&response=" . $recaptcha_response );
            
            $g_response = json_decode( $response );
            
            if ( $g_response-&gt;success !== true ) {
                echo '{ "alert": "error", "message": "Captcha not Validated! Please Try Again." }';
                die;
            }
        }
        
        // Uncomment the following Lines of Code if you want to Force reCaptcha Validation
        
        if( !isset( $_POST['g-recaptcha-response'] ) ) {
        	echo '{ "alert": "error", "message": "Captcha not Submitted! Please Try Again." }';
        	die;
        }
        
        $mail-&gt;MsgHTML( $body );
        $sendEmail = $mail-&gt;Send();
        
        if( $sendEmail == true ):
        echo '{ "alert": "success", "message": "' . $message_success . '" }';
        else:
        echo '{ "alert": "error", "message": "Email **could not** be sent due to some Unexpected Error. Please Try Again later.&lt;br /&gt;&lt;br /&gt;**Reason:**&lt;br /&gt;' . $mail-&gt;ErrorInfo . '" }';
        endif;
    } else {
        echo '{ "alert": "error", "message": "Bot **Detected**.! Clean yourself Botster.!" }';
    }
} else {
    echo '{ "alert": "error", "message": "Please **Fill up** all the Fields and Try Again." }';
}

} else {
echo '{ "alert": "error", "message": "An unexpected error occured. Please Try Again later." }';
}

?>


				&lt;div class="col_half"&gt;
					&lt;div class="fancy-title title-dotted-border"&gt;
						&lt;h3&gt;Send us an Email&lt;/h3&gt;
					&lt;/div&gt;
					&lt;div class="contact-widget"&gt;
						&lt;div class="contact-form-result"&gt;&lt;/div&gt;
						&lt;form class="nobottommargin" id="template-contactform" name="template-contactform" action="include/sendemail.php" method="post"&gt;
							&lt;div class="form-process"&gt;&lt;/div&gt;
							&lt;div class="col_one_third"&gt;
								&lt;label for="template-contactform-name"&gt;Name &lt;small&gt;*&lt;/small&gt;&lt;/label&gt;
								&lt;input type="text" id="template-contactform-name" name="template-contactform-name" value="" class="sm-form-control required" /&gt;
							&lt;/div&gt;
							&lt;div class="col_one_third"&gt;
								&lt;label for="template-contactform-email"&gt;Email &lt;small&gt;*&lt;/small&gt;&lt;/label&gt;
								&lt;input type="email" id="template-contactform-email" name="template-contactform-email" value="" class="required email sm-form-control" /&gt;
							&lt;/div&gt;
							&lt;div class="col_one_third col_last"&gt;
								&lt;label for="template-contactform-phone"&gt;Phone&lt;/label&gt;
								&lt;input type="text" id="template-contactform-phone" name="template-contactform-phone" value="" class="sm-form-control" /&gt;
							&lt;/div&gt;
							&lt;div class="clear"&gt;&lt;/div&gt;
							&lt;div class="col_two_third"&gt;
								&lt;label for="template-contactform-subject"&gt;Subject &lt;small&gt;*&lt;/small&gt;&lt;/label&gt;
								&lt;input type="text" id="template-contactform-subject" name="template-contactform-subject" value="" class="required sm-form-control" /&gt;
							&lt;/div&gt;
							&lt;div class="col_one_third col_last"&gt;
								&lt;label for="template-contactform-service"&gt;Services&lt;/label&gt;
								&lt;select id="template-contactform-service" name="template-contactform-service" class="sm-form-control"&gt;
									&lt;option value=""&gt;- Select One -&lt;/option&gt;
									&lt;option value="General"&gt;General&lt;/option&gt;
									&lt;option value="Realty"&gt;Realty&lt;/option&gt;
									&lt;option value="Wealth"&gt;Wealth&lt;/option&gt;
									&lt;option value="Other"&gt;Other&lt;/option&gt;
								&lt;/select&gt;
							&lt;/div&gt;
							&lt;div class="clear"&gt;&lt;/div&gt;
							&lt;div class="col_full"&gt;
								&lt;label for="template-contactform-message"&gt;Message &lt;small&gt;*&lt;/small&gt;&lt;/label&gt;
								&lt;textarea class="required sm-form-control" id="template-contactform-message" name="template-contactform-message" rows="6" cols="30"&gt;&lt;/textarea&gt;
							&lt;/div&gt;
							&lt;div class="col_full hidden"&gt;
								&lt;input type="text" id="template-contactform-botcheck" name="template-contactform-botcheck" value="" class="sm-form-control" /&gt;
							&lt;/div&gt;
							&lt;div class="col_full"&gt;
								&lt;button class="button button-3d nomargin" type="submit" id="template-contactform-submit" name="template-contactform-submit" value="submit"&gt;Send Message&lt;/button&gt;
							&lt;/div&gt;
						&lt;/form&gt;
						&lt;div class="g-recaptcha" data-sitekey="6LexD0UUAAAAABZSxJdoetSErccgjppDO7NCymyO"&gt;&lt;/div&gt;
					&lt;/div&gt;
				&lt;/div&gt;
SSemicolon WebSTAFFMar 8, 2018

Hello,

We have checked out your Website and the Codes. This does not work because the reCaptcha Code is outside the <form> Container. Make sure that you have added the code inside the <form> Container to avoid any issues.

This will definitely fix the issue. Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

BBlunt_HausMar 9, 2018

Hi Support Team,

I have added the recaptha inside the <form> however even after the change it still does the same thing.

If i do not select verify in the recaptcha and try and submit the form, i get the error that the message cannot be sent - which is 100% correct.

However, if I then decide to select the verify recaptcha after getting the error without refereshing the page it refuses to send.

Is there a way for the form or page to reset so that the user doesnt have to refresh the entire webpage before submitting the form if they happen to miss the recaptha when submitting the first time?

Your help is greatly appreciated.

Thank you!

SSemicolon WebSTAFFMar 9, 2018

Hello,

We have just checked out your Contact Form and it appears to be working fine for us at the moment with the reCaptcha working properly. Thanks for your Patience.

Do let us know if we can help you with anything else or if you find any further issues with Canvas.

BBlunt_HausMar 10, 2018

It still doesn't do what its supposed to, can i ask that you try and complete the form without clicking on the recaptcha, you will notice the error message appear.

Then, without refreshing the page, after the error message appears, verify the recaptcha and try and submit the form.

You will see that it does not send...

Please help.

SSemicolon WebSTAFFMar 12, 2018

Hello,

We have tried as you have mentioned and still everything works fine. Can you please consider clearing your Browser Cache and trying again as it might fix the issue on your end.

Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

BBlunt_HausMar 12, 2018

Thank you support team, it seems to be working fine.

My apologies.

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard