From e4d6705fefa99303baee94f3c9ed7ea01041f2c4 Mon Sep 17 00:00:00 2001 From: Gary Date: Wed, 14 May 2025 14:48:09 +0100 Subject: [PATCH] updated contact from --- contact.php | 61 +++++++++++++++++++++++++++++++++++++++++---- includes/header.php | 1 + 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/contact.php b/contact.php index 7ff51dd..69a8746 100644 --- a/contact.php +++ b/contact.php @@ -9,6 +9,50 @@ include_once $URlcorrection . "includes/header.php"; include_once $URlcorrection . "includes/nav.php"; include_once $URlcorrection . "includes/banner.php"; + +// Generate a new CAPTCHA question if not set +if (!isset($_SESSION['captcha'])) { + $_SESSION['captcha'] = [ + 'num1' => rand(1, 10), + 'num2' => rand(1, 10), + 'answer' => 0 // This will be calculated later + ]; + $_SESSION['captcha']['answer'] = $_SESSION['captcha']['num1'] + $_SESSION['captcha']['num2']; +} + +// Check if form is submitted +if ($_SERVER["REQUEST_METHOD"] == "POST") { + $name = trim($_POST['name']); + $email = trim($_POST['email']); + $subject = trim($_POST['subject']); + $message = trim($_POST['message']); + $captcha_input = isset($_POST['captcha']) ? (int)$_POST['captcha'] : 0; + + // Validate CAPTCHA + if ($captcha_input !== $_SESSION['captcha']['answer']) { + echo "
Incorrect CAPTCHA answer. Please try again.
"; + } else { + // Send the email + $to = "gary@uklb.co.uk"; // TEST EMAIL DESTINATION + $headers = "From: $email" . "\r\n" . "Reply-To: $email" . "\r\n" . "X-Mailer: PHP/" . phpversion(); + $body = "You have received a new message from $name.\n\n" . "Subject: $subject\n\n" . "Message:\n$message"; + + if (mail($to, $subject, $body, $headers)) { + echo "
Thank you for contacting us. We will get back to you shortly.
"; + } else { + echo "
There was an error sending your message. Please try again.
"; + } + + // Generate a new CAPTCHA for the next submission + $_SESSION['captcha'] = [ + 'num1' => rand(1, 10), + 'num2' => rand(1, 10), + 'answer' => 0 + ]; + $_SESSION['captcha']['answer'] = $_SESSION['captcha']['num1'] + $_SESSION['captcha']['num2']; + } +} + ?> @@ -21,26 +65,33 @@ include_once $URlcorrection . "includes/banner.php";

Get in touch

-
+
- +
- +
- +
- + +
+
+
+ +
+ +
diff --git a/includes/header.php b/includes/header.php index 551ff6b..850e0d1 100644 --- a/includes/header.php +++ b/includes/header.php @@ -4,6 +4,7 @@