<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $fname = htmlspecialchars($_POST['fname'] ?? '');
    $lname = htmlspecialchars($_POST['lname'] ?? '');
    $email = htmlspecialchars($_POST['email'] ?? '');
    $phone = htmlspecialchars($_POST['phone'] ?? '');
    $comments = htmlspecialchars($_POST['comments'] ?? '');



    $html =  "<h2>Data Received Form The Columbia</h2>";
    $html .= "First Name: $fname<br>";
    $html .= "Last Name: $lname<br>";
    $html .= "Email: $email<br>";
    $html .= "Phone: $phone<br>";
    $html .= "Comments: $comments<br>";


    $mail = new PHPMailer(true);

    try {
        //Server settings
        $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
        $mail->isSMTP();                                            //Send using SMTP
        $mail->Host       = 'smtp.gmail.com';                     //Set the SMTP server to send through
        $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
        $mail->Username   = 'dev.ahs@productions-dev.com';                     //SMTP username
        $mail->Password   = 'Qwer@123!@#';                               //SMTP password
        $mail->SMTPSecure = 'tls';            //Enable implicit TLS encryption
        $mail->Port       = 587;                                    //TCP port to connect to; use 587 if you have set 
    
        //Recipients
        $mail->setFrom('dev.ahs@productions-dev.com', 'Mailer');
        $mail->addAddress('omer@jumpto1.com');     //Add a recipient
        $mail->addAddress('dev.ahs@productions-dev.com');               //Name is optional
      
    
       
        //Content
        $mail->isHTML(true);                                  //Set email format to HTML
        $mail->Subject = 'Here is the subject';
        $mail->Body    = $html;
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    
        $mail->send();
        echo "<script> window.location.href = https://wp24.cryscampus.com/thecolumbiabuildingco/pages//pages/thank-you.html' </script>";
        //header('location : https://wp24.cryscampus.com/thecolumbiabuildingco/pages//pages/thank-you.html');
    } catch (Exception $e) {
        echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
    }


} else {
    echo "Form not submitted.";
}
?>