Forum Moderators: coopster
<script src='https://www.google.com/recaptcha/api.js'></script> <form action="../thank-you2.php" method="post" name="contact_form" onsubmit="return validate_form()" id="contact_form" >
<div>
<div >
<input name="name" placeholder="Name" type="text" />
</div>
<div>
<input name="email" placeholder="Email" type="text" />
</div>
</div>
<div>
<div>
<div class="g-recaptcha" data-sitekey="(site key here)"></div>
</div>
</div>
<div>
<div >
<label for="submit"></label>
<input type="submit" value="Submit" class="submit" name="submit" />
</div>
</div>
</form> <?php if(isset($_POST['submit'])) {
$to = "me@example.com";
$subject = "Free Estimate Contact Form";
$name = $_POST['name'];
$email = $_POST['email'];
$captcha = $_POST['g-recaptcha-response'];
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$secretKey = "(secret key here)";
$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 are spammer ! Get the @$%K out</h2>';
} else {
$body = "Name: $name\n
E-Mail: $email\n
echo "<h2>Your request has been submitted</h2>";
$from = "From: contact@example.com";
mail($to, $subject, $body, $from);
}
}
?>