reverting back

This commit is contained in:
Gary 2025-06-17 11:55:05 +01:00
parent 8f0dab9da5
commit 93224850f8

View File

@ -10,36 +10,33 @@ include_once $URlcorrection . "includes/header.php";
include_once $URlcorrection . "includes/banner.php";
include_once $URlcorrection . "includes/nav.php";
// Generate CAPTCHA numbers
$num1 = rand(1, 10);
$num2 = rand(1, 10);
$captchaAnswer = $num1 + $num2;
// Generate a new CAPTCHA question if not set
if (!isset($_SESSION['captcha'])) {
$_SESSION['captcha'] = [
'num1' => rand(1, 10),
'num2' => rand(1, 10),
'answer' => $_SESSION['captcha']['num1'] + $_SESSION['captcha']['num2']
];
}
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['submit'])) {
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$subject = trim($_POST['subject']);
$message = trim($_POST['message']);
$captcha_input = isset($_POST['captcha']) ? (int)$_POST['captcha'] : 0;
$submittedAnswer = isset($_POST['captcha_answer']) ? (int)$_POST['captcha_answer'] : null;
if ($captcha_input !== $submittedAnswer) {
$errorMessage = "Incorrect CAPTCHA answer. Please try again.";
// Store form data for re-population
$storedName = $name;
$storedEmail = $email;
$storedPhone = $phone;
$storedSubject = $subject;
$storedMessage = $message;
if ($captcha_input !== $_SESSION['captcha']['answer']) {
echo "<div class='alert alert-danger text-center'>Incorrect CAPTCHA answer. Please try again.</div>";
} else {
$to = " enquiries@warmseal-roofing.co.uk";
$website_name = "Warmseal contact";
$to = "enquiries@warmseal-roofing.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 Bedford Wealth Contact 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)) {
@ -49,28 +46,19 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['submit'])) {
"Message:\n" . $message;
if (mail($to, 'New Message from ' . $website_name, $body, $headers)) {
header("Location: submission");
exit();
echo "<div class='alert alert-success text-center'>Thank you for contacting us. We will get back to you shortly.</div>";
} else {
$errorMessage = "There was an error sending your message. Please try again.";
// Store form data for re-population
$storedName = $name;
$storedEmail = $email;
$storedPhone = $phone;
$storedSubject = $subject;
$storedMessage = $message;
echo "<div class='alert alert-danger text-center'>There was an error sending your message. Please try again.</div>";
}
}
} else {
// Initialize stored data as empty on initial load
$storedName = '';
$storedEmail = '';
$storedPhone = '';
$storedSubject = '';
$storedMessage = '';
$errorMessage = null;
}
// 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']
];
}
?>