From 5623df8797d4f3758b7f49efbe835d86645a364c Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 27 Mar 2025 14:28:56 +0100 Subject: [PATCH] =?UTF-8?q?A=C3=B1adido=20archivos=20EmailServies.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ci4/app/Services/EmailService.php | 58 +++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 ci4/app/Services/EmailService.php 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; + } +}