. */ namespace SP\Providers\Mail; use DI\Container; use PHPMailer\PHPMailer\PHPMailer; use SP\Providers\Provider; use SP\Util\Util; /** * Class MailProvider * * @package SP\Providers\Mail */ final class MailProvider extends Provider { /** * @var PHPMailer */ private $mailer; /** * @var bool */ private $debug = false; /** * Inicializar la clase PHPMailer. * * @param MailParams $mailParams * * @return PHPMailer * @throws MailProviderException */ public function getMailer(MailParams $mailParams) { $appName = Util::getAppInfo('appname'); try { $this->mailer->SMTPAutoTLS = false; $this->mailer->isSMTP(); $this->mailer->CharSet = 'utf-8'; $this->mailer->Host = $mailParams->server; $this->mailer->Port = $mailParams->port; if ($mailParams->mailAuthenabled) { $this->mailer->SMTPAuth = true; $this->mailer->Username = $mailParams->user; $this->mailer->Password = $mailParams->pass; } $this->mailer->SMTPSecure = strtolower($mailParams->security); if ($this->debug) { $this->mailer->SMTPDebug = 2; $this->mailer->Debugoutput = function ($str, $level) { logger($str, strtoupper($level)); }; } $this->mailer->setFrom($mailParams->from, $appName); $this->mailer->addReplyTo($mailParams->from, $appName); $this->mailer->WordWrap = 100; return $this->mailer; } catch (\Exception $e) { processException($e); throw new MailProviderException( __u('No es posible inicializar'), MailProviderException::ERROR, $e->getMessage(), $e->getCode(), $e ); } } /** * @return bool */ public function isDebug() { return $this->debug; } /** * @param bool $debug */ public function setDebug($debug) { $this->debug = (bool)$debug; } /** * @param Container $dic * * @throws \DI\DependencyException * @throws \DI\NotFoundException */ protected function initialize(Container $dic) { $this->mailer = $dic->get(PHPMailer::class); } }