<?php
// require_once $_SERVER['DOCUMENT_ROOT'] . "/Assets/Classes/PHPMailer.php";
// require_once $_SERVER['DOCUMENT_ROOT'] . "/Assets/Classes/SMTP.php";
// require_once $_SERVER['DOCUMENT_ROOT'] . "/Assets/Classes/Exception.php";

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

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

class email
{

    function __construct()
    {
    }



    function send_mail(array $emails, array $names, $message, $subject = "!WARNING!")
    {


        try {


            $mail = new PHPMailer(true);

            //Server settings
            $mail->isSMTP();
            $mail->Host       = "mail.elegantwork.co.za";
            $mail->SMTPAuth   = true;
            $mail->Username   = "no-reply@elegantwork.co.za";
            $mail->Password   = "XR26ooQ;Pk3.";
            $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
            $mail->Port       = 465;
            $mail->SMTPDebug  = 0;

            //Recipients

            $mail->setFrom('no-reply@lowveldnuts.co.za', 'Lowveld Nuts (Pty) Ltd');


            $mail->isHTML(true);
            $index = 0;
            foreach ($emails as $email) {
                $email . '->' . $names[$index];
                $mail->addAddress($email, $names[$index]);
                $index++;
            }

            $mail->Subject = $subject;



            $mail->Body = "$message";

            $mail->Body .=  "<br><br><br><br><hr><br> <h1> Sent by Elegant Work Group Auto Mailer </h1> <bbr><br> <b> Please note this email address is unattended </b>";





            // ALTIRNATIVE //
            return$mail->send();

        } catch (Exception $e) {

            echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
        }
    }
}
