$success, 'message' => $message, 'captcha' => $_SESSION['captcha_question'] ]); exit; } // CSRF protection if (!hash_equals($_SESSION['contact_csrf'] ?? '', $_POST['csrf'] ?? '')) { respond(false, 'Invalid request. Please refresh the page.'); } // Honeypot spam protection if (!empty($_POST['website'])) { respond(true, 'Your message has been submitted.'); } // Basic rate limiting if (isset($_SESSION['last_contact']) && time() - $_SESSION['last_contact'] < 10) { respond(false, 'Please wait a few seconds before trying again.'); } $name = trim($_POST['name'] ?? ''); $email = trim($_POST['email'] ?? ''); $phone = trim($_POST['phone'] ?? ''); $subject = trim($_POST['subject'] ?? ''); $message = trim($_POST['message'] ?? ''); $captcha = trim($_POST['captcha'] ?? ''); // Validation if ($name === '' || $email === '' || $phone === '' || $subject === '' || $message === '' || $captcha === '') { respond(false, 'Please fill in all fields.'); } if (strlen($name) > 100 || strlen($subject) > 150 || strlen($phone) > 30 || strlen($message) > 10000) { respond(false, 'One or more fields are too long.'); } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { respond(false, 'Please enter a valid email address.'); } if (!preg_match('/^\+?[0-9\s().-]{7,30}$/', $phone)) { respond(false, 'Please enter a valid phone number.'); } if (!hash_equals( (string)$_SESSION['captcha_answer'], $captcha )) { respond(false, 'Incorrect CAPTCHA answer. Please try again.'); } // Prepare email $safeSubject = str_replace(["\r", "\n"], '', $subject); $mailSubject = 'Contact Form: ' . $safeSubject; if (function_exists('mb_encode_mimeheader')) { $mailSubject = mb_encode_mimeheader( $mailSubject, 'UTF-8', 'B' ); } // Visitor information $ip = $_SERVER['REMOTE_ADDR'] ?? 'Unknown'; $referrer = $_SERVER['HTTP_REFERER'] ?? 'Direct / Unknown'; $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? 'Unknown'; $timestamp = date('Y-m-d H:i:s T'); $mailBody = "New Contact Form Submission\n\n" . "Name: $name\n" . "Email: $email\n" . "Phone: $phone\n" . "Subject: $subject\n\n" . "Message:\n$message\n". " VISITOR INFORMATION ------------------- IP Address : $ip Referrer : $referrer User Agent : $userAgent Timestamp : $timestamp ========================= "; $headers = [ "From: Website Contact <{$fromEmail}>", "Reply-To: {$email}", "MIME-Version: 1.0", "Content-Type: text/plain; charset=UTF-8", "X-Mailer: PHP/" . phpversion() ]; // Send email if (mail($toEmail, $mailSubject, $mailBody, implode("\r\n", $headers))) { $_SESSION['last_contact'] = time(); respond(true, 'Thank you! Your message has been sent successfully.'); } respond(false, 'Unable to send your message. Please try again later.'); } ?> Welcome to <?php echo $domain; ?>

Get in Touch

Have questions or want to know more? Feel free to contact us. We would love to hear from you.

Email Us
contact @

Contact Us

Fill out the form below and we will get back to you as soon as possible.