<?php
include 'config.php';

function text_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

include 'mailer/vendor/autoload.php';

use PHPMailer\PHPMailer\PHPMailer;

require_once "mailer/PHPMailer.php";
require_once "mailer/SMTP.php";
require_once "mailer/Exception.php";

 function sendMail($email, $subject, $message){
    global $sitename, $site_url;
    $mail = new PHPMailer();
    //SMTP Settings (use default cpanel email account)
    $mail->isSMTP();
    $mail->Host = "smtp.hostinger.com"; //
    $mail->SMTPAuth = true;
    $mail->Username = "info@globalpostexpress.com"; // Default cpanel email account
    $mail->Password = 'Nwichiam.'; // Default cpanel email password
    $mail->Port = 465; // 587
    $mail->SMTPSecure = "ssl"; // tls

    //Email Settings
    $mail->isHTML(true);
    $mail->setFrom('info@globalpostexpress.com', $sitename); // Email address/ Bank bane shown to reciever
    $mail->addAddress($email);
    $mail->AddReplyTo("info@globalpostexpress.com", $sitename); // Email address/ Bank bane shown to reciever
    $mail->Subject = $subject;
    // Email Template
    $htmlTemplate = '
    <div style="font-family: Arial, sans-serif; background-color: #f9f9f9; padding: 20px;">
        <div style="max-width: 600px; margin: auto; background-color: #ffffff; border-radius: 8px; overflow: hidden; box-shadow: 0 4px 10px rgba(0,0,0,0.05);">
            <div style="background-color: #004080; padding: 20px; text-align: center;">
                <img src="'.$site_url.'/assets/img/logo.png" alt="Logo" style="max-width: 150px;">
            </div>
            <div style="padding: 30px;">
                ' . $message . '
            </div>
            <div style="background-color: #f1f1f1; padding: 20px; text-align: center; font-size: 12px; color: #777;">
                &copy; ' . date("Y") . ' '.$sitename.'. All rights reserved.<br>
                <a href="'.$site_url.'" style="color: #004080; text-decoration: none;">Visit our website</a>
            </div>
        </div>
    </div>';

    $mail->MsgHTML($htmlTemplate);
    $send = $mail->Send();
    return $send;
}

?>
