catcha should now update

This commit is contained in:
Gary 2025-05-14 15:21:39 +01:00
parent 176b9676a0
commit 10d090d106

View File

@ -22,7 +22,7 @@ if (!isset($_SESSION['captcha'])) {
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']); // Assuming you have a phone input field
$phone = trim($_POST['phone']);
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
$captcha_input = isset($_POST['captcha']) ? (int)$_POST['captcha'] : 0;
@ -30,16 +30,16 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
if ($captcha_input !== $_SESSION['captcha']['answer']) {
echo "<div class='alert alert-danger text-center'>Incorrect CAPTCHA answer. Please try again.</div>";
} else {
$to = "gary@uklb.co.uk"; // TEST EMAIL DESTINATION
$website_name = "Warmseal Roofing contact"; // Replace with your actual website name
$from_email = "noreply@" . $_SERVER['HTTP_HOST']; // A common practice for website forms
$to = "gary@uklb.co.uk";
$website_name = "Warmseal Roofing contact";
$from_email = "noreply@" . $_SERVER['HTTP_HOST'];
$headers = "From: " . $website_name . " <" . $from_email . ">" . "\r\n" .
"Reply-To: " . $name . " <" . $email . ">" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
$body = "You have received a new message from your website form:\n\n" .
$body = "You have received a new message from Warmseal Roofing Contact form:\n\n" .
"Name: " . $name . "\n" .
"Email: " . $email . "\n";
if (!empty($phone)) { // Only include phone number if it's provided
if (!empty($phone)) {
$body .= "Phone Number: " . $phone . "\n";
}
$body .= "Subject: " . $subject . "\n\n" .
@ -47,15 +47,17 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (mail($to, 'New Message from ' . $website_name, $body, $headers)) {
echo "<div class='alert alert-success text-center'>Thank you for contacting us. We will get back to you shortly.</div>";
$_SESSION['captcha'] = [
'num1' => rand(1, 10),
'num2' => rand(1, 10),
'answer' => $_SESSION['captcha']['num1'] + $_SESSION['captcha']['num2']
];
} else {
echo "<div class='alert alert-danger text-center'>There was an error sending your message. Please try again.</div>";
}
}
// Generate a new CAPTCHA for the next submission AFTER processing the form
$_SESSION['captcha'] = [
'num1' => rand(1, 10),
'num2' => rand(1, 10),
'answer' => $_SESSION['captcha']['num1'] + $_SESSION['captcha']['num2']
];
}
?>