<?php

$URlcorrection = "";
$PageTitle = "Contact Us";
$Page = "contact";
$ometa['description'] = "Warmseal Roofing: Your trusted roofing specialists in the UK, offering expert roof repairs, installations, and maintenance with quality workmanship and guaranteed results.";
$ometa['keywords'] = "roofing, roof repairs, roof installation, roofing specialists, roofing maintenance, quality workmanship, guaranteed results, UK roofing, Warmseal Roofing, contact warmseal roofing, roofing services, roofing experts, roofing contractors, roof maintenance, roof installation, roof repairs, roofing solutions, roofing company, roofing professionals, roofing estimates, roofing quotes, roofing consultations";
include_once $URlcorrection . "includes/header.php";

include_once $URlcorrection . "includes/banner.php";
include_once $URlcorrection . "includes/nav.php";

// 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") {
	$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;

	if ($captcha_input !== $_SESSION['captcha']['answer']) {
		echo "<div class='alert alert-danger text-center'>Incorrect CAPTCHA answer. Please try again.</div>";
	} else {
		$to = "info@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 Warmseal Roofing Contact form:\n\n" .
			"Name: " . $name . "\n" .
			"Email: " . $email . "\n";
		if (!empty($phone)) {
			$body .= "Phone Number: " . $phone . "\n";
		}
		$body .= "Subject: " . $subject . "\n\n" .
			"Message:\n" . $message;

		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>";
		} 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']
	];
}

?>

<section class="ftco-section bg-light">
	<div class="container">
		<div class="row justify-content-center">
			<div class="col-md-12">
				<div class="wrapper">
					<div class="row no-gutters">
						<div class="col-md-7 d-flex">
							<div class="contact-wrap w-100 p-md-5 p-4">
								<h3 class="mb-4">Get in touch</h3>
								<form method="POST" id="contactForm" class="contactForm">
									<div class="row">
										<div class="col-md-6">
											<div class="form-group">
												<input type="text" class="form-control" name="name" id="name" placeholder="Name" required>
											</div>
										</div>
										<div class="col-md-6">
											<div class="form-group">
												<input type="email" class="form-control" name="email" id="email" placeholder="Email" required>
											</div>
										</div>
										<div class="col-md-12">
											<div class="form-group">
												<input type="text" class="form-control" name="phone" id="phone" placeholder="Phone Number" required>
											</div>
										</div>
										<div class="col-md-12">
											<div class="form-group">
												<input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" required>
											</div>
										</div>
										<div class="col-md-12">
											<div class="form-group">
												<textarea name="message" class="form-control" id="message" cols="30" rows="7" placeholder="Message" required></textarea>
											</div>
										</div>
										<div class="col-md-12">
											<div class="form-group">
												<label for="captcha">Security Check: What is <?php echo $_SESSION['captcha']['num1']; ?> + <?php echo $_SESSION['captcha']['num2']; ?>?</label>
												<input type="number" id="captcha" name="captcha" class="form-control" required>
											</div>
										</div>
										<div class="col-md-12">
											<div class="form-group">
												<input type="submit" value="Send Message" class="btn btn-primary">
												<div class="submitting"></div>
											</div>
										</div>
									</div>
								</form>
							</div>
						</div>
						<div class="col-md-5 d-flex align-items-stretch">
							<div class="info-wrap bg-primary w-100 p-lg-5 p-4">
								<h3 class="mb-4 mt-md-4">Contact us</h3>
								<div class="dbox w-100 d-flex align-items-start">

								</div>
								<div class="dbox w-100 d-flex align-items-center">
									<div class="icon d-flex align-items-center justify-content-center">
										<span class="fa fa-phone"></span>
									</div>
									<div class="text pl-3">
										<p><span>Phone:</span> <a href="tel:07458190308">07458190308</a></p>
									</div>
								</div>
								<div class="dbox w-100 d-flex align-items-center">
									<div class="icon d-flex align-items-center justify-content-center">
										<span class="fa fa-paper-plane"></span>
									</div>
									<div class="text pl-3">
										<p><span>Email:</span> <a href="mailto:enquiries@warmseal-roofing.co.uk">enquiries@warmseal-roofing.co.uk</a></p>
									</div>
								</div>
								<div class="dbox w-100 d-flex align-items-center">
									<div class="icon d-flex align-items-center justify-content-center">
										<span class="fa fa-globe"></span>
									</div>
									<div class="text pl-3">
										<p><span>Website:</span> <a href="https://warmseal-roofing.co.uk">warmseal-roofing.co.uk</a></p>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</section>


<?php
include_once $URlcorrection . "includes/footer.php";
?>