<?php
declare(strict_types=1);

namespace App\Services;

final class MailerService
{
    public static function send(string $toEmail, string $subject, string $html = '', string $text = '', ?string $toName = null): void
    {
        $cfg = require __DIR__ . '/../../config/mail.php';

        $client = new SmtpClient(
            (string)$cfg['smtp_host'],
            (int)$cfg['smtp_port'],
            (string)$cfg['smtp_secure'],   // 'ssl' or 'tls'
            (string)$cfg['smtp_user'],
            (string)$cfg['smtp_pass']
        );

        $client->send(
            (string)$cfg['from_email'],
            (string)$cfg['from_name'],
            $toEmail,
            $toName ?: '',
            $subject,
            $html,
            $text
        );
    }
}
