';
//print_r($_POST);
//exit;
date_default_timezone_set('Asia/Kolkata');
/* ---------- SAFE STOP FUNCTION ---------- */
function stop($msg = 'Invalid request') {
echo "";
exit;
}
/* ---------- GET DATA ---------- */
$name = trim($_POST['name'] ?? '');
$phone = trim($_POST['phone'] ?? '');
$email = trim($_POST['email'] ?? '');
$source = "Home Page Popup";
/* ---------- BASIC REQUIRED ---------- */
if ($name === '' || $phone === '') {
stop('Please fill required fields');
}
/* ---------- NAME VALIDATION ---------- */
if (!preg_match('/^[A-Za-z ]{2,20}$/', $name)) {
stop('Invalid name');
}
/* ---------- PHONE VALIDATION ---------- */
if (!preg_match('/^[6-9][0-9]{9}$/', $phone)) {
stop('Invalid phone number');
}
/* ---------- EMAIL VALIDATION ---------- */
if ($email !== '' && !filter_var($email, FILTER_VALIDATE_EMAIL)) {
stop('Invalid email');
}
/* ---------- STRONG SPAM BLOCK ---------- */
$spamWords = ['http', 'www', '.ru', '.xyz', 'btc', 'usd', 'rub', '€', '$', '💳'];
$checkText = strtolower($name . ' ' . $email);
foreach ($spamWords as $word) {
if (strpos($checkText, $word) !== false) {
stop('Spam detected');
}
}
/* ---------- RATE LIMIT (60 sec) ---------- */
if (isset($_SESSION['last_submit']) && time() - $_SESSION['last_submit'] < 60) {
stop('Please wait before submitting again');
}
$_SESSION['last_submit'] = time();
/* ---------- SAVE TO DATABASE ---------- */
$stmt = $conn->prepare(
"INSERT INTO enquiries (name, phone, email, source)
VALUES (?, ?, ?, ?)"
);
$stmt->bind_param("ssss", $name, $phone, $email, $source);
$stmt->execute();
$stmt->close();
/* ---------- SEND EMAIL ---------- */
$mail = new PHPMailer(true);
try {
$mail->isSMTP();
$mail->Host = 'smtp.hostinger.com';
$mail->SMTPAuth = true;
$mail->Username = 'enquiry@dholeraresidentialplot.com';
$mail->Password = '9;vf*Yh2cV';
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;
$mail->setFrom('enquiry@dholeraresidentialplot.com', 'Dholera Residential Plots Enquiry');
$mail->addAddress('rohitpariharntl@gmail.com');
$mail->addAddress('daksh@omanaprojects.com');
$mail->isHTML(true);
$mail->Subject = 'New Call Back Enquiry';
$mail->Body = "
Name: {$name}
Phone: {$phone}
Email: " . ($email ?: 'Not provided');
$mail->send();
if ($email !== '') {
$mail->clearAddresses();
$mail->addAddress($email);
$mail->Subject = 'Thank you for contacting Dholera Residential Plots';
$mail->Body = "Dear {$name},
We will contact you shortly.";
$mail->send();
}
} catch (Exception $e) {
// ignore mail errors
}
/* ---------- SUCCESS ---------- */
echo "";