<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Company email
$to = "contact@chiacai.com"; // <-- Replace with your company email
// Collect form fields
$name = htmlspecialchars(trim($_POST["fname"]));
$email = htmlspecialchars(trim($_POST["email"]));
$org = htmlspecialchars(trim($_POST["org"]));
$message = htmlspecialchars(trim($_POST["message"]));
// Subject
$subject = "New Contact Form Submission from $name";
// Email body
$body = "
You have received a new message from your website chiac asi contact form:
Name: $name
Email: $email
Organisation: $org
Message:
$message
";
// Headers
$headers = "From: $name <$email>\r\n";
$headers .= "Reply-To: $email\r\n";
// Default message
$alertMessage = "";
// Validate required fields
if (empty($name) || empty($email)) {
$alertMessage = "Name and Email are required.";
} else {
// Try sending email
if (mail($to, $subject, $body, $headers)) {
$alertMessage = "✅ Message sent successfully!";
} else {
$alertMessage = "❌ Sorry, something went wrong. Please try again later.";
}
}
// Show alert + redirect
echo "<script>
alert('$alertMessage');
window.location.href='contactus.php';
</script>";
}
?>