diff --git a/ci4/app/Services/EmailService.php b/ci4/app/Services/EmailService.php new file mode 100644 index 00000000..74caed35 --- /dev/null +++ b/ci4/app/Services/EmailService.php @@ -0,0 +1,58 @@ +first()->toArray(); + $gateway = $config['email_gateway']; + $body = html_entity_decode($body); + + if ($gateway === 'smtp') { + try { + $email = Services::email(); + + $emailConfig = [ + 'protocol' => $config['email_gateway'], + 'SMTPHost' => $config['email_smtp'], + 'SMTPUser' => $config['email_address'], + 'SMTPPass' => $config['email_pass'], + 'SMTPPort' => (int) $config['email_port'], + 'SMTPCrypto' => $config['email_cert'] === 'none' ? '' : $config['email_cert'], + 'SMTPTimeout' => 15, + 'mailType' => 'html', + 'wordWrap' => true, + ]; + + $email->initialize($emailConfig); + + $email->setFrom($config['email_address'], $config['email_name']); + $email->setTo($recipient); + $email->setSubject($subject); + $email->setMessage($body); + + return $email->send(); + } catch (\Throwable $e) { + log_message('error', 'EmailService failed: ' . $e->getMessage()); + return false; + } + } + + return false; + } +}