I cant seeem to get this form to work, currently it acts as though its working but not recieving any mail?
<form method="post" action="action_page.php" novalidate>
<label for="name">Name</label>
<input name="name" id="name" type="text" required>
<label for="email">Email</label>
<input name="email" id="email" type="email" required>
<label for="message">Message</label>
<textarea name="message" id="message" placeholder="" required></textarea>
<div id="important">
<label for="human">What is 2+2?</label>
<input name="human" id="human" placeholder="">
</div>
<div id="contact-footer">
<p>Your email address will only be used to reply to your message and
your personal information
will never be shared.</p>
</div>
<div id="form-flex">
<div class="g-recaptcha-con">
<div class="g-recaptcha" data-sitekey="6Ldkew0qAAAAAMQHlmn177hTXLtVcZ9fkmVxLqqL"></div>
</div>
<div class="submit-div">
<input type="submit" id="submit" class="button" name="submit" value="Send Message">
</div>
</div>
</form>
<?php
if (isset($_POST['submit'])) {
// reCAPTCHA validation
if (isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) {
// Google secret API key
$secretAPIkey = '6Ldkew0qAAAAANFhvgiOKViu_tduZTncnXJ8dRXi';
// reCAPTCHA response verification
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secretAPIkey . '&response=' . $_POST['g-recaptcha-response']);
$responseData = json_decode($verifyResponse);
if ($responseData->success) {
// Check if the anti-spam field is filled
if (!empty($_POST['human'])) {
// If the anti-spam field is filled, consider it spam and don't send the email
echo "<h2>Spam detected!</h2>";
echo "<p>Your message has been flagged as spam and not sent.</p>";
} else {
// Send email
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = '[email protected]';
$subject = 'Message';
$headers = "From: $emailrn";
$headers .= "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";
$body = "From: $namern";
$body .= "E-Mail: $emailrn";
$body .= "Message:rn $message";
if (mail($to, $subject, $body, $headers)) {
echo '<p>Your message has been sent successfully!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
}
} else {
echo '<p>reCAPTCHA verification failed. Please try again.</p>';
}
} else {
echo '<p>Please complete the reCAPTCHA.</p>';
}
} else {
echo '<p>Form not submitted properly.</p>';
}
?>
At firt the recaptcha check was in the wrong place and the form was sending without having to complete it, I changed it to check recapcha first before processing the rest of the form, now it takes me to action_page.php as though its sent but I am not recieiving any mail now, it was before.