PHP mailer not working with ReCAPTCHA v. 2

the mail() function

Moderators: gesf, Michalio

Post Reply
2sheaPHPhelp

Hello,

Last year I installed a PHP bootstrap contact form with ReCAPTCHA that I downloaded from this link:

http://reusableforms.com/d/a/bootstrap-contact-form-recaptcha

I installed and it worked fine.

Now it seems that it no longer works. After hitting the submit button after establishing that I am not a robot, I get a “Verification expired. Check the checkbox again” message. Below is the link to the form.

https://ich-builders.com/contact.html

I can check the checkbox again but it will result int the same message. I checked the error log and it came up with this:

failed to open stream: no suitable wrapper could be found in /home/jnb5r8f3ts7f/public_html/src/ReCaptchaValidator.php on line 40

The line 40 in the ReCaptchaValidator.php file is the following:

$resp_raw = file_get_contents($url);

I am not a PHP coder, so I don’t know how to fix this. If it will help, here is the complete code in the ReCaptchaValidator.php file below:

Thank you

Code: Select all

<?php
namespace FormGuide\Handlx;

class ReCaptchaValidator
{
	private $enabled;
	private $secret;
	public function __construct()
	{
		$this->enabled=false;
	}
	
	public function isEnabled()
	{
		return $this->enabled;	
	}

	public function enable($enable)
	{
		$this->enabled = $enable;
	}

	public function initSecretKey($key)
	{
		$this->secret = $key;
	}

	public function validate()
	{
		if(empty($_POST['g-recaptcha-response']))
		{
			return false;
		}

		$captcha=$_POST['g-recaptcha-response'];

		$url = 
		'https://www.google.com/recaptcha/api/siteverify?secret='.$this->secret.'&response='.$captcha.'&remoteip='.$_SERVER['REMOTE_ADDR'];

		$resp_raw = file_get_contents($url);

		$response=json_decode($resp_raw, true);

		if(!empty($response['success']) && $response['success'])
		{
			return true;
		}
		return false;
	}
}
Post Reply