<?php
session_start();
require("includes/email-credentials.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 ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['full_name']) && !empty($_POST['email_address']) && !empty($_POST['subject']) && !empty($_POST['message']) && isset($_SESSION['form-id']) && ($_SESSION['form-id'] == "iuibfbjaklsiabs")) {

	$name = $_POST['full_name'];
	$email = $_POST['email_address'];
	$subject = $_POST['subject'];
	$message = $_POST['message'];

	$mail = new PHPMailer();

	try {

		//Server settings        
		$mail->Host = $support_smtp_host;
		$mail->SMTPAuth = true;
		$mail->SMTPSecure = $support_smtp_encryption;
		$mail->Username = $support_smtp_username;
		$mail->Password = $support_smtp_password;
		$mail->Port = $support_smtp_port;
		$mail->setFrom($email);
		$mail->addAddress($support_smtp_email);
		$mail->Subject = $subject;
		$mail->isHTML(true);
		$mail->Body = "
		<h2>$subject</h2>
		<p><b>Full Name:</b> $name</p>
		<p><b>Email Address:</b> $email</p>
		<p><b>Message:</b> $message</p>

		";

		$mail->send();
		die('success');
	} catch (Exception $e) {
		die("An unexpected error occurred. Please try again.");
	}
} else {
	die("Invalid request.");
}