<?php

namespace App\Utils;

use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;

class Utils
{
    public function sendEmail(MailerInterface $mailer, Address $from, Address $to, string $subject, string $content)
    {
        //$dsn = "smtp://{$_ENV['MAIL_USER']}:{$_ENV['MAIL_PWD']}@{$_ENV['MAIL_SERVER']}:{$_ENV['MAIL_PORT']}";
        //dump($_ENV['MAILER_DSN']);
        //$_ENV['MAILER_DSN'] = $dsn;
        //dump($_ENV['MAILER_DSN']);
        //die;

        $mail = (new Email())
            ->from($from)
            ->to($to)
            ->subject($subject)
            ->replyTo($from)
            ->html($content);

        try {
            $mailer->send($mail);
        } catch (TransportExceptionInterface $e) {
            die($e->getMessage());
            // some error prevented the email sending; display an
            // error message or try to resend the message
        }
    }
}
