<?php

require_once "../../../php/Mail.php"; // Ensure the PEAR Mail package is included
require_once "../../../php/Mail/mime.php"; //Include Mail_Mime
require_once "../../../php/Mail/mimePart.php"; //Include Mail_Mime
require_once "../../../php/Net/SMTP.php";
require_once "../../../php/Net/Socket.php";

class EmailSender {
    private $smtp;

    public function __construct($email_conn) {
        $this->smtp = Mail::factory("smtp", [
            "host" => $email_conn["host"],
            "port" => $email_conn["port"],
            "auth" => true,
            "username" => $email_conn["mailUsername"],
            "password" => $email_conn["mailPassword"]
        ]);
    }

    public function sendEmail($from, $to, $subject, $body) {
        $headers = [
            "From" => $from,
            "To" => $to,
            "Subject" => $subject
        ];

        $mail = $this->smtp->send($to, $headers, $body);

        if (PEAR::isError($mail)) {
            echo "Error: " . $mail->getMessage();
            echo "Debug Info: " . print_r($mail, true);
        } else {
            echo "Success!";
        }   
    }
}

?>