I get a message that says the form was submitted successfully, but no email is received. My current contact form works but I get too much spam. I tried modifying with recaptcha examples from here, but none seem to show how to actually send an email with the information entered in the contact form. Here is my PHP code:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$token = $_POST['token'];
$action = $_POST['action'];
$from = 'Glass & Tile Works Website';
$to = 'glassandtileworks@gmail.com';
$subject = 'New website lead';
$body = "From: $name\n E-Mail: $email\n Message:\n $message\n Phone:\n $phone";
if ($_POST['submit']) {
$curlData = array(
'secret' => 'My secret key',
'response' => $token
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.google.com/recaptcha/api/siteverify");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($curlData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curlResponse = curl_exec($ch);
$captchaResponse = json_decode($curlResponse, true);
if ($captchaResponse['success'] == '1' && $captchaResponse['action'] == $action &&
$captchaResponse['score'] >= 0.5 && $captchaResponse['hostname'] == $_SERVER['SERVER_NAME']) {
echo 'Form Submitted Successfully';
} else {
echo 'You are not a human';
}
}