<?php include "include/header.php";?>

<?php


if (isset($_POST['send_contact'])) {

    // Sanitize inputs
    $name    = htmlspecialchars(trim($_POST['sender_name']));
    $subject = htmlspecialchars(trim($_POST['sender_subject']));
    $email   = filter_var($_POST['sender_email'], FILTER_VALIDATE_EMAIL);
    $message = htmlspecialchars(trim($_POST['sender_mssg']));

    // Validation
    if (!$name || !$subject || !$email || !$message) {
        echo "<script>alert('All fields are required.');</script>";
        exit;
    }

    // Email content
    $mailSubject = "Contact Form: $subject";

    $mailBody = "
        <h3>New Contact Message</h3>
        <p><strong>Name:</strong> $name</p>
        <p><strong>Email:</strong> $email</p>
        <p><strong>Subject:</strong> $subject</p>
        <p><strong>Message:</strong></p>
        <p>$message</p>
    ";

    // Headers
    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8\r\n";
    $headers .= "From: $sitename <$adminemail>\r\n";

    // Send mail
    if (mail($adminemail, $mailSubject, $mailBody, $headers)) {
        echo "<script>alert('Message sent successfully. We will contact you shortly.'); window.location.href='".$_SERVER['PHP_SELF']."';</script>";
        exit;
    } else {
        echo "<script>alert('Failed to send message. Please try again later.');</script>";
    }
}
?>


<!-- Page Content - Only Page Elements Here-->
		<div class="page-content footer-clear">

			<!-- Page Title-->
			<div class="pt-3">
				<div class="page-title d-flex">
					<div class="align-self-center">
						<a href="#" data-back-button class="me-3 ms-0 icon icon-xxs bg-theme rounded-s shadow-m">
							<i class="bi bi-chevron-left color-theme font-14"></i>
						</a>
					</div>
					<div class="align-self-center me-auto">
						<!-- <p id="wel" class="font-14 mb-n1">Welcome Back</p> -->
						<h1 style="margin-top: 25px;" class="font-24">Contact US</h1>
					</div>

				</div>
			</div>

			<div class="card card-style">
				<div class="content">
					<form method="POST" action="">
						<h4>Contact US</h4>
						<p class="mb-0">
							Contact Us Now and Get a Swift Response.
						</p>

						<div class="form-custom form-label form-icon mb-3 mt-5">
							<i class="bi bi-person-circle font-14"></i>
							<input name="sender_name" type="text" class="form-control rounded-xs" id="c1"
								placeholder="John Doe" />
							<label for="c1" class="color-highlight form-label-always-active">Sender Name</label>
						</div>

						<div class="form-custom form-label form-icon mb-3 mt-5">
							<i class="bi bi-exclamation-circle font-14"></i>
							<input type="text" name="sender_subject" class="form-control rounded-xs" id="c1" />
							<label for="c1" class="color-highlight form-label-always-active">Subject</label>
						</div>

						<div class="form-custom form-label form-icon mb-3 mt-5">
							<i class="bi bi-envelope-at font-14"></i>
							<input type="email" name="sender_email" class="form-control rounded-xs" id="c1"
								placeholder="Your Email" />
							<label for="c1" class="color-highlight form-label-always-active">Sender Email</label>
						</div>

						<div class="row">
							<div class="col-12">
								<div class="form-group form-label mb-3">
									<textarea style="border-radius: 8px; background: transparent;"
										placeholder="Mail Here" name="sender_mssg" class="form-control" rows="3"
										required="required"></textarea>
								</div>
							</div>
						</div>

						<div class="divider mt-2 mb-4"></div>
						<button type="submit" name="send_contact" class="btn btn-full gradient-highlight shadow-bg shadow-bg-s">
                            Send Mail
                        </button>
					</form>
					<!-- End of Tab Wrapper-->
				</div>
			</div>

		</div>
		<!-- End of Page Content-->
		
		
<script src="scripts/bootstrap.min.js"></script>
<script src="scripts/custom.js"></script>
</body></html>