config->transport === 'smtp') { $this->configureSmtp($mail); } else { $mail->isMail(); } $mail->setFrom($this->config->fromAddress, $this->config->fromName); $mail->addAddress($to); $mail->Subject = $subject; $mail->isHTML(false); $mail->Body = $body; $mail->send(); } catch (PhpMailerException $e) { throw new MailException('Failed to send email: ' . $e->getMessage(), 0, $e); } } private function configureSmtp(PHPMailer $mail): void { $mail->isSMTP(); $mail->Host = (string) $this->config->smtpHost; $mail->Port = $this->config->smtpPort; if ($this->config->smtpUsername !== null) { $mail->SMTPAuth = true; $mail->Username = $this->config->smtpUsername; $mail->Password = (string) $this->config->smtpPassword; } switch ($this->config->smtpEncryption) { case 'ssl': $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; break; case 'none': $mail->SMTPSecure = ''; $mail->SMTPAutoTLS = false; break; default: $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; } } }