mailer = new PHPMailer(true); $this->mailer->isSMTP(); $this->mailer->Host = $config['host']; $this->mailer->Port = $config['port']; $this->mailer->SMTPAuth = filter_var($config['auth'], FILTER_VALIDATE_BOOLEAN); $this->mailer->SMTPAutoTLS = $config['encryption']; $this->mailer->Username = $config['user']; $this->mailer->Password = $config['password']; $this->mailer->SMTPSecure = $config['encryption']; $this->mailer->CharSet = self::CHARSET; $this->mailer->SMTPOptions = [ 'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ] ]; $this->mailer->Timeout = 30; $this->mailer->setFrom($config['noreply']); } public function send( string $subject, string $body, array $emails, array $attachments = [], bool $isGroupLetter = false ): void { try { $this->mailer->smtpConnect(); $this->mailer->isHTML(); $this->mailer->Subject = $subject; $this->mailer->Body = $body; foreach ($attachments as $attachment) { $this->mailer->addAttachment($attachment['path'], $attachment['name']); } if ($isGroupLetter) { foreach ($emails as $email) { $this->mailer->addAddress($email); } $this->mailer->send(); $this->mailer->clearAddresses(); } else { foreach ($emails as $email) { $this->mailer->addAddress($email); $this->mailer->send(); $this->mailer->clearAddresses(); } } } catch (\Throwable $th) { throw $th; } finally { $this->mailer->smtpClose(); } } }