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

require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';

function sendEmail($toEmail, $subject, $bodyHtml) {
    //Create an instance; passing `true` enables exceptions
    $mail = new PHPMailer(true);

    try {
        //Server settings
        $mail->SMTPDebug = SMTP::DEBUG_OFF; // Turn off debugging; set to SMTP::DEBUG_SERVER for verbose output
        $mail->isSMTP();                                         // Send using SMTP
        $mail->Host       = 'server62.web-hosting.com';          // Set the SMTP server to send through
        $mail->SMTPAuth   = true;                                // Enable SMTP authentication
        $mail->Username   = 'dkananza@quantacubeenergy.com';     // SMTP username
        $mail->Password   = 'Malawi@100%';                     // SMTP password
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;         // Enable implicit TLS encryption
        $mail->Port       = 465;                                 // TCP port to connect to; use 587 for STARTTLS

        //Recipients
        $mail->setFrom('dkananza@quantacubeenergy.com', 'Your Name'); // Sender's email and name
        $mail->addAddress($toEmail);                          // Recipient's email and name

        //Content
        $mail->isHTML(true);                    // Set email format to HTML
        $mail->Subject = $subject;              // Email subject
        $mail->Body    = $bodyHtml;             // HTML body content
        //$mail->AltBody = $bodyText;             // Plain text body content

        $mail->send();
        echo 'Message has been sent';
    } catch (Exception $e) {
        echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
    }
}

// Example usage of the function
//sendEmail('mwezzie@gmail.com', 'Joe User', 'Here is the subject', 'This is the HTML message body <b>in bold!</b>', 'This is the body in plain text for non-HTML mail clients');
?>
