<?php
 
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
 
require 'phpmailer/src/Exception.php';
require 'phpmailer/src/PHPMailer.php';
require 'phpmailer/src/SMTP.php';
 
if (isset($_POST["submit_form"])) {
    try {
        // Retrieve input values from the form
        $name = $_POST['name'];
        $phone = $_POST['phone'];
        $email = $_POST['email'];
        $project_id = $_POST['project_id'];
        $website_url = $_POST['website_url'];
        // Assuming other fields are not relevant for the email
 
        $mail = new PHPMailer(true);
        $mail->isSMTP();                                          // Send using SMTP
        $mail->Host = 'email-smtp.ap-south-1.amazonaws.com';                         // Set the SMTP server to send through
        $mail->SMTPAuth = true;                                   // Enable SMTP authentication
        $mail->Username = 'AKIA6AHUV2JB7GEN7TM6';                   // SMTP username
        $mail->Password = 'BEFp9HXqsbwOU/qTB8hZffBUCInpTW4ZG0g4Y161kSE9';                   // SMTP password
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;          // Enable implicit TLS encryption
        $mail->Port = 465;                                        // TCP port to connect to
 
        $mail->setFrom('noreply@realtyassistant.in', 'Realty Assistant Lead');
        $mail->addAddress('suraj.bondre@thedigibee.in', 'Suraj bondre');
         $mail->addAddress('raj@thedigibee.in', 'Raj');
           $mail->addAddress('prachi.singh@thedigibee.in', 'Prachi Singh');
          $mail->addAddress('anand@realtyassistant.in', 'anand');
        $mail->isHTML(true);                                      // Set email format to HTML
        $mail->Subject = 'Contact Us Form Failure : Lead captured for project - ' . $project_id;
        // Include input values in the email body
        $mail->Body = 'Name: ' . $name . '<br>Phone: ' . $phone . '<br>Email: ' . $email . '<br>Project id: ' . $project_id . '<br>Website: ' . $website_url;
        $mail->AltBody = 'Name: ' . $name . '\nPhone: ' . $phone . '\nEmail: ' . $email . '\nProject id: ' . $project_id . '\nWebsite: ' . $website_url;
 
        $mail->send();
    //    echo 'Message has been sent';
 
        // Redirect to the landing page after sending the email
        header('Location: thank-you.php?message=Thank you for your query. We will contact you soon');
        exit(); // Stop further execution of the script
    } catch (Exception $e) {
        echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
    }
}