PATH:
home
/
u865795251
/
domains
/
whatisnewis.com
/
public_html
/
homestays
/
Editing: send_mail.php
<?php // Set headers for JSON response header('Content-Type: application/json'); // Restore silent error handling for production error_reporting(0); ini_set('display_errors', 0); /** * PHPMailer Form Handler for Homestays Ludhiana * * Instructions: * 1. Download PHPMailer from https://github.com/PHPMailer/PHPMailer * 2. Place it in a folder named 'PHPMailer' in your project root. * 3. Update the SMTP settings below with your actual email details. */ // Import PHPMailer classes into the global namespace use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; // Update these paths to where you placed the PHPMailer files require 'PHPMailer/src/Exception.php'; require 'PHPMailer/src/PHPMailer.php'; require 'PHPMailer/src/SMTP.php'; // Form configurations $admin_email = "amandeepdigitalhandlersindia@gmail.com"; // YOUR ADMIN EMAIL $site_name = "Homestays Ludhiana"; // Check if form is submitted if ($_SERVER["REQUEST_METHOD"] == "POST") { // Sanitize input safely with null coalescing $name = strip_tags(trim($_POST["name"] ?? '')); $email = filter_var(trim($_POST["email"] ?? ''), FILTER_SANITIZE_EMAIL); $phone = strip_tags(trim($_POST["phone"] ?? '')); $checkin = strip_tags(trim($_POST["checkin"] ?? '')); $checkout = strip_tags(trim($_POST["checkout"] ?? '')); $guests = strip_tags(trim($_POST["guests"] ?? '')); $rooms_count = strip_tags(trim($_POST["rooms_count"] ?? '')); $room = strip_tags(trim($_POST["room"] ?? '')); $message = strip_tags(trim($_POST["message"] ?? '')); // Validate (Simple check) if (empty($name) || empty($phone)) { echo json_encode(["status" => "error", "message" => "Please fill in all required fields."]); exit; } $mail = new PHPMailer(true); try { // --- SMTP Settings (Update these!) --- $mail->isSMTP(); $mail->Host = 'smtp.gmail.com'; // Set the SMTP server to send through $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'amandeepdigitalhandlersindia@gmail.com'; // SMTP username $mail->Password = 'jncl gpax seec rqnj'; // SMTP password $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; $mail->Port = 587; // TCP port to connect to // Recipients $mail->setFrom($mail->Username, $site_name); // MUST use Gmail address here for reliability $mail->addAddress($admin_email, 'Admin'); if (!empty($email)) { $mail->addReplyTo($email, $name); } // Content $mail->isHTML(true); $mail->Subject = "New Inquiry from $name - $site_name"; $body = " <h2>New Booking Inquiry</h2> <p><strong>Name:</strong> $name</p> <p><strong>Email:</strong> " . ($email ?: 'Not provided') . "</p> <p><strong>Phone:</strong> $phone</p> <p><strong>Check-in:</strong> $checkin</p> <p><strong>Check-out:</strong> $checkout</p> <p><strong>Guests:</strong> $guests</p> <p><strong>Number of Rooms:</strong> $rooms_count</p> <p><strong>Room Type:</strong> $room</p> <p><strong>Message:</strong><br>$message</p> "; $mail->Body = $body; $mail->AltBody = strip_tags($body); $mail->send(); echo json_encode(["status" => "success", "message" => "Thank you! Your inquiry has been sent."]); } catch (Exception $e) { echo json_encode(["status" => "error", "message" => "Mailer Error: " . $mail->ErrorInfo . " | System Error: " . $e->getMessage()]); } } else { echo json_encode(["status" => "error", "message" => "Forbidden."]); } ?>
SAVE
CANCEL