<?php

namespace App\Helpers;

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

class MailHelper
{
    public static function sendEmail($to, $subject, $body)
    {
        $mail = new PHPMailer(true);
        
        try {
            // SMTP Configuration
            $mail->isSMTP();
            //$mail->Host       = env('MAIL_HOST', 'mail.hawkssolutions.com'); 
            $mail->Host       = 'mail.hawkssolutions.com'; 
            $mail->SMTPAuth   = true;
            // $mail->Username   = env('MAIL_USERNAME'); 
            // $mail->Password   = env('MAIL_PASSWORD'); 
            $mail->Username   = 'contact@hawkssolutions.com'; 
            $mail->Password   = '1EMvr}FvxD^g'; 
            $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Change to PHPMailer::ENCRYPTION_SMTPS for SSL
            //$mail->Port       = env('MAIL_PORT', 587);
            $mail->Port       = 465;

            // Sender & Recipient
            //$mail->setFrom(env('MAIL_FROM_ADDRESS'), env('MAIL_FROM_NAME'));
            $mail->setFrom('contact@hawkssolutions.com');
            $mail->addAddress($to);
            $mail->isHTML(true);
            $mail->Subject = $subject;
            $mail->Body    = $body;
            
            // Send Email
            $mail->send();
            return 'Email sent successfully!';
        } catch (Exception $e) {
            return "Email could not be sent. Error: {$mail->ErrorInfo}";
        }
    }
}
