updated contact from
This commit is contained in:
parent
493b7a12ab
commit
e4d6705fef
61
contact.php
61
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 "<div class='alert alert-danger text-center'>Incorrect CAPTCHA answer. Please try again.</div>";
|
||||
} 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 "<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
|
||||
$_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";
|
||||
<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">
|
||||
<form method="POST" id="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">
|
||||
<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">
|
||||
<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="subject" id="subject" placeholder="Subject">
|
||||
<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"></textarea>
|
||||
<textarea name="message" class="form-control" id="message" cols="30" rows="7" placeholder="Message" required></textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<!-- Custom CAPTCHA -->
|
||||
<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">
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
<head>
|
||||
<?php
|
||||
include_once "meta/meta.php";
|
||||
session_start();
|
||||
?>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user