<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/autoload.php';
require 'includes/stmp.php';

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

    $name = htmlspecialchars($_POST['name']);
    $email = htmlspecialchars($_POST['email']);
    $phone = htmlspecialchars($_POST['phone']);
    $subject = htmlspecialchars($_POST['subject']);
    $message = htmlspecialchars($_POST['message']);

    $mail = new PHPMailer(true);

    try {

        // SMTP Settings
       $mail = getMailer();

        // Sender & Receiver
        $mail->setFrom('info@icleanlaundromat.com', 'iClean Website');
        $mail->addReplyTo($email, $name);
        $mail->addAddress('info@icleanlaundromat.com');

        // Email Content
        $mail->isHTML(true);
        $mail->Subject = $subject;

        $mail->Body = "
            <h3>New Contact Message</h3>
            <p><strong>Name:</strong> {$name}</p>
            <p><strong>Email:</strong> {$email}</p>
            <p><strong>Phone:</strong> {$phone}</p>
            <p><strong>Subject:</strong> {$subject}</p>
            <p><strong>Message:</strong><br>{$message}</p>
        ";

        $mail->send();

        echo "success";
        exit();

    } catch (Exception $e) {

        echo "error";
        exit();
    }
}
?>