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

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

function sendEmail($to, $subject, $body)
{
    $mail = new PHPMailer(true);
    
    try {
        $mail->isSMTP();
        $mail->Host = 'sandbox.smtp.mailtrap.io';
        $mail->SMTPAuth = true;
        $mail->Port = 2525;
        $mail->Username = 'fe44e40615a147';
        $mail->Password = '4082c12a149f84';
        $mail->SMTPSecure = 'tls';
        
        $mail->setFrom('supriyaba.webplanex@gmail.com', 'webplanex');
        $mail->addAddress($to);

        $mail->isHTML(true);
        $mail->Subject = $subject;
        $mail->Body = $body;

        $mail->send();
        return true;
    } catch (Exception $e) {
        error_log("Email sending failed: {$mail->ErrorInfo}");
        return false;
    }
}

function generateEmailTemplate($templateFile, $replaceValues)
{
    $html = file_get_contents($templateFile);

    foreach ($replaceValues as $placeholder => $value) {
        $html = str_replace('{{' . $placeholder . '}}', $value, $html);
    }

    return $html;
}
?>