diff --git a/contact.php b/contact.php
index 5807e90..c6b7a90 100644
--- a/contact.php
+++ b/contact.php
@@ -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 "
Incorrect CAPTCHA answer. Please try again.
";
} 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 "Thank you for contacting us. We will get back to you shortly.
";
- $_SESSION['captcha'] = [
- 'num1' => rand(1, 10),
- 'num2' => rand(1, 10),
- 'answer' => $_SESSION['captcha']['num1'] + $_SESSION['captcha']['num2']
- ];
} else {
echo "There was an error sending your message. Please try again.
";
}
}
+
+ // 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']
+ ];
}
?>