File: /home/u665686179/domains/hometuitionacademy.com/public_html/email.php
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Collect and sanitize input
$name = htmlspecialchars(trim($_POST['name']));
$phone = htmlspecialchars(trim($_POST['phone']));
$course = htmlspecialchars(trim($_POST['course']));
$school = isset($_POST['school']) ? htmlspecialchars(trim($_POST['school'])) : '';
$college = isset($_POST['college']) ? htmlspecialchars(trim($_POST['college'])) : '';
$query = isset($_POST['query']) ? htmlspecialchars(trim($_POST['query'])) : '';
// Validation
$errors = [];
if (empty($name)) {
$errors[] = "Name is required.";
}
if (empty($phone) || !preg_match('/^\d{10}$/', $phone)) {
$errors[] = "Phone is required and must be a 10-digit valid number.";
}
if (!empty($errors)) {
echo "<p style='color:red;'>".implode("<br>", $errors)."</p>";
exit;
}
// Prepare email
$to = "your-email@example.com"; // Replace with your email
$subject = "New Enquiry: Private Tutor Form Submission";
$body = "
<h3>Form Submission Details:</h3>
<p><strong>Name:</strong> $name</p>
<p><strong>Phone:</strong> $phone</p>
<p><strong>School:</strong> $school</p>
<p><strong>College:</strong> $college</p>
<p><strong>Course:</strong> $course</p>
<p><strong>Query:</strong> $query</p>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: no-reply@example.com" . "\r\n"; // Replace with your domain's email
// Send email
if (mail($to, $subject, $body, $headers)) {
echo "<p style='color:green;'>Thank you for your submission. We will contact you shortly!</p>";
} else {
echo "<p style='color:red;'>Sorry, there was an error sending your message. Please try again later.</p>";
}
}
?>