• I’m using the latest version Contact Form 7.

    When I added recaptcha field to the form, I got error, couldn’t send email. But, when I removed recaptcha field, the form worked fine.

    I checked by adding the following code after the line 81 in modules\recaptcha.php:

    var_dump($response)

    and got the result:

    object(WP_Error)#5494 (2) {
      ["errors"]=>
      array(1) {
        ["http_request_failed"]=>
        array(1) {
          [0]=>
          string(35) "cURL error 6: name lookup timed out"
        }
      }
      ["error_data"]=>
      array(0) {
      }
    }

    So, I tried to solve this issue by replaced the “verify” function with the following functions:

    public function verify( $response_token ) {
    		$is_human = false;
    
    		if ( empty( $response_token ) ) {
    			return $is_human;
    		}
    
    		$url = self::VERIFY_URL;
            $sitekey = $this->get_sitekey();
            $secret = $this->get_secret( $sitekey );
            $response = file_get_contents($url ."?secret=" . $secret . "&response=" . $response_token . "&remoteip=" .$_SERVER['REMOTE_ADDR']);
    
            if ( 200 != $this->parseHeaders($http_response_header)["reponse_code"] ) {
                return $is_human;
            }
    		
    		$response = json_decode( $response, true );
    
    		$is_human = isset( $response['success'] ) && true == $response['success'];
    		return $is_human;
    	}
    	
    	private	function parseHeaders( $headers ) {
            $head = array();
            foreach( $headers as $k=>$v )
            {
                $t = explode( ':', $v, 2 );
                if( isset( $t[1] ) )
                    $head[ trim($t[0]) ] = trim( $t[1] );
                else
                {
                    $head[] = $v;
                    if( preg_match( "#HTTP/[0-9\.]+\s+([0-9]+)#",$v, $out ) )
                        $head['reponse_code'] = intval($out[1]);
                }
            }
            return $head;
        }

    Thus, the form works well with recaptcha. 🙂

The topic ‘Contact Form 7: reCaptcha Issue’ is closed to new replies.