Recaptcha issue - "connection-failed" error

Hi
I’m trying to get a php mail form (phpmailer) to work on my test site but it fails with the error message of “connection-failed”
I am using google recaptcha and have done a couple of other sites using the exact same php files so really stuck as to what to try.
I have created the 2 google recaptcha keys and put them in the config.php file along with the 16 key google password for the SMTP email

I did see this topic from a few months ago with the exact same issue but that seemed to be a temporary issue - [ReCaptcha connection-failed on server side verify - tried all RequestMethods]

I have added the line
AddHandler php5-cgi .html
into the .htaccess file within the htdocs folder

The 2 files that need to be amended to make this work are config.php and submit.php
config.php (1.5 KB)
submit.php (3.1 KB)

From the error trapping, I can see that I get as far as the last line of the code below in submit.php:

> <?php
> 
> require_once __DIR__.'/vendor/autoload.php';
> require_once __DIR__.'/functions.php';
> require_once __DIR__.'/config.php';
> 
> session_start();
> 
> // Basic check to make sure the form was submitted.
> if ($_SERVER['REQUEST_METHOD'] != 'POST') {
>     redirectWithError("The form must be submitted with POST data.");
> }
> 
> // Do some validation, check to make sure the name, email and message are valid.
> if (empty($_POST['g-recaptcha-response'])) {
>     redirectWithError("Please complete the CAPTCHA.");
> }
> 
> $recaptcha = new \ReCaptcha\ReCaptcha(CONTACTFORM_RECAPTCHA_SECRET_KEY);
> $resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_REQUEST['REMOTE_ADDR']);
> 
> if (!$resp->isSuccess()) {
>     $errors = $resp->getErrorCodes();
>     $error = $errors[0];
> 
>     $recaptchaErrorMapping = [
>         'missing-input-secret' => 'No reCAPTCHA secret key was submitted.',
>         'invalid-input-secret' => 'The submitted reCAPTCHA secret key was invalid.',
>         'missing-input-response' => 'No reCAPTCHA response was submitted.',
>         'invalid-input-response' => 'The submitted reCAPTCHA response was invalid.',
>         'bad-request' => 'An unknown error occurred while trying to validate your response.',
>         'timeout-or-duplicate' => 'The request is no longer valid. Please try again.',
>     ];
> 
>     $errorMessage = $recaptchaErrorMapping[$error];
>     redirectWithError("Please retry the CAPTCHA: ".$error);

I’m sure that more info might well be needed to help diagnose what the problem actually is so please let me know as any help is really appreciated

thanks

Could you please check which PHP version your account is on? The easiest way to do that is to create a PHP file on your website with the contents <?php phpinfo(); and opening that.

If you’re on PHP 8.1, please note that some extensions are still missing. It’s possible that some of these extensions are necessary for SMTP to work (I think OpenSSL is quite critical).

https://forum.infinityfree.com/t/various-php-extensions-missing-on-php-8-1/73538/2

6 Likes

hi
It shows PHP version: 8.1.16
the other site I’ve been creating is showing 7.4.8

My current site was working 2 weeks ago but not sure what version it would have been on at that time.
Apologies for asking, but how do the websites get updated? Is it on a rolling basis?

is there anything I can do in the meantime?
thanks

(sorry meant to add that my other site using 7.4.8 had the php mailer working properly)

We started upgrading servers last week. So it seems extremely likely that this is a PHP 8.1 problem, which is why it stopped working

Servers are indeed upgraded on a rolling basis.

Not really. You could backup everything on this account, remove the domain from this account and set it up on a new account and hope that you’ll get PHP 7.4.

5 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.