Contact us
We love hearing from travelers, journalists, and partners. Use the form below to send a message. We respond to most queries within 2–3 business days.
PHP 8.3 contact form endpoint (ready to deploy)
Host this endpoint on your server, set form action to point at it, and configure CORS if posting cross-origin. It implements server-side validation, a strong time-based HMAC CAPTCHA, and sends the email to domainadmin@hitmedia.in, From: info@sambhajinagar.in.
<?php
// contact.php — PHP 8.3 endpoint
// Place on your server and update FORM_ACTION to your URL in contact.html
declare(strict_types=1);
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { exit; }
function respond(int $code, array $payload): void {
http_response_code($code);
echo json_encode($payload);
exit;
}
$input = json_decode(file_get_contents('php://input'), true) ?? [];
$name = trim($input['name'] ?? '');
$email = filter_var($input['email'] ?? '', FILTER_VALIDATE_EMAIL);
$phone = trim($input['phone'] ?? '');
$subject = trim($input['subject'] ?? '');
$message = trim($input['message'] ?? '');
$hp_company = trim($input['hp_company'] ?? '');
$captcha_token = $input['captcha_token'] ?? '';
if ($hp_company !== '') { respond(400, ['error' => 'Spam detected']); }
if (!$email || $name === '' || $subject === '' || $message === '') { respond(422, ['error' => 'Validation failed']); }
// Strong CAPTCHA: HMAC(time-windowed) with server secret
$secret = 'change_this_server_secret';
[$ts, $hmac, $answer] = explode('.', (string)$captcha_token) + [null, null, null];
if (!$ts || !$hmac || !$answer) { respond(400, ['error' => 'Invalid token']); }
if (abs(time() - (int)$ts) > 600) { respond(400, ['error' => 'Expired challenge']); }
$expected = hash_hmac('sha256', $ts . '|' . $answer, $secret);
if (!hash_equals($expected, $hmac)) { respond(400, ['error' => 'Captcha failed']); }
$to = 'domainadmin@hitmedia.in';
$headers = [
'From: info@sambhajinagar.in',
'Reply-To: ' . ($email ?: 'info@sambhajinagar.in'),
'Content-Type: text/plain; charset=UTF-8',
];
$body = "Name: $name\nEmail: $email\nPhone: $phone\nSubject: $subject\n\n$message\n";
$ok = mail($to, 'Website contact: ' . $subject, $body, implode("\r\n", $headers));
if ($ok) { respond(201, ['success' => true]); }
respond(500, ['error' => 'Mail failed']);