<?php

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

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

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

    $email = htmlspecialchars($_POST['email']);

    $mail = new PHPMailer(true);

    try {

        // SMTP Settings
       $mail = getMailer();

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

        // Email Content
        $mail->isHTML(true);
        $mail->Subject = "New Newsletter Subscription";

         $mail->Body = "
            <h3>New Newsletter Subscriber</h3>
            <p><strong>Email:</strong> {$email}</p>
        ";

        $mail->send();

        echo "success";
        exit();

    } catch (Exception $e) {

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