migrate email to use Util class and method
This commit is contained in:
parent
717b9398bc
commit
97d656912c
35
src/Utils/Utils.php
Normal file
35
src/Utils/Utils.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user