Jump to content

So I am trying to implement Goggle reCAPTCHA into my HTML contact form with PHP validation, but I keep getting this error:

 

FATAL ERROR: USING $THIS WHEN NOT IN OBJECT CONTEXT IN/HOME/ASHWELM/PUBLIC_HTML/EZEEFIXPC.COM/FORM.PHP ON LINE 12

 

But I don't know what is happening.

 

Here is my HTML:

 

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
	<head>
    <link rel="shortcut icon" href="images/favicon.ico" />
		<title>EzeeFixPC</title>
        <meta charset="utf-8"/>
		<link rel="stylesheet" href="assets/css/main.css" />
        <script src='https://www.google.com/recaptcha/api.js'></script>
                            <script>
function validateForm() {
    var x = document.forms["contact"]["email"].value;
    var atpos = x.indexOf("@");
    var dotpos = x.lastIndexOf(".");
    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) {
        alert("Not a valid e-mail address");
        return false;      
    }                        
}                          
                    </script>
                    	
    </head>
	<body>
    <div class="loader"></div>

		<!-- Header -->
			<header id="header">
				<div class="inner">
					<a href="index.html" class="logo">EzeeFixPC</a>
					<nav id="nav">
						<a href="index.html">Home</a>
						<a href="services.html">Services</a>
                        <a href="about.html">About</a>
                        <a href="customers.html">Customers</a>
                        <a href="partners.html">Partners</a>
                        <a href="media_services.html">Media Services</a>
						<a href="contact.html">Contact</a>
					</nav>
				</div>
			</header>
			<a href="#menu" class="navPanelToggle"><span class="fa fa-bars"></span></a>

		<!-- Main -->
			<section id="main">
				<div class="inner">
                	<header>
					<h2>Contact</h2>
					</header>
					<form name="contact" method="post" action="form.php" onsubmit="return validateForm();">
						<div class="field">
							<label for="name">Name</label>
							<input type="text" name="name" id="name" />
						</div>
						<div class="field">
							<label for="email">Email</label>
							<input type="text" name="email" id="email" />
						</div>
						<div class="field">
							<label for="message">Message</label>
							<textarea name="message" id="message" rows="10"></textarea>
						</div>
                        <div class="g-recaptcha" data-sitekey="6LeSHwcUAAAAADhShPBUWNmX2Et9smafxUMzLFFT"></div>
						<ul class="actions">
							<li><input type="submit" value="Send Message" class="alt" /></li>
						</ul>
					</form>	
				</div>
			</section>

		<!-- Footer -->
			<section id="footer">
				<div class="inner">				
					<div class="copyright">
                       <h6>
                         &copy; Design by <a href="http://mikeashwell.com/">EzeefixPC.com</a>.
                         <img src="images/xhtml-verified.png" alt="" width="88" />
                       </h6>
                    </div>
				</div>
			</section>

		<!-- Scripts -->
			<script src="assets/js/jquery.min.js"></script>
			<script src="assets/js/skel.min.js"></script>
			<script src="assets/js/util.js"></script>
			<script src="assets/js/main.js"></script>

	</body>
</html>

And here is my PHP:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="contact.html; charset=utf-8" />
<link rel="stylesheet" href="assets/css/main.css" />
<link rel="shortcut icon" href="images/favicon.ico" />
<title>Confirmation Page</title>
</head>
<body><h1><center>
<?php
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->page);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $this->pageSource = curl_exec($ch);
        curl_close($ch);

        $name = $_POST['name'];
        $email = $_POST['email'];
	    $subject ='Web form enquiry';
        $message = $_POST['message'];
	    $to = 'test@gmail.com';
        $captcha = $_POST['g-recaptcha-response'];
		
		$headers = "From: ".$email . "\r\n" . "CC: test@gmail.com";

        $secretKey = "secret key";
        $ip = $_SERVER['REMOTE_ADDR'];
        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
        $responseKeys = json_decode($response,true);
        if(intval($responseKeys["success"]) !== 1) {
          echo '<h2>You answered the captcha incorrectly!</h2>';
        } else {
			if (mail ($to, $subject, $message, $headers)) {
				echo '<p>Your message has been sent!</p>';
				}
		}
?>
</body></h1></center>
</html>

Thanks.

Link to comment
https://linustechtips.com/topic/665026-help/
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×