From cfefb8cc56755381a22f2c6c054e575896080710 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Sun, 14 Dec 2025 17:21:48 +0200 Subject: [PATCH] Adds email helper for sending emails --- app/helpers/email_helper.php | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 app/helpers/email_helper.php diff --git a/app/helpers/email_helper.php b/app/helpers/email_helper.php new file mode 100644 index 0000000..002ffd9 --- /dev/null +++ b/app/helpers/email_helper.php @@ -0,0 +1,60 @@ + $value) { + $content = str_replace('{{' . $key . '}}', $value, $content); + } + + return $content; +} + +/** + * Send email using template + * + * @param string $to Recipient email + * @param string $subject Email subject + * @param string $templateName Template name + * @param array $variables Template variables + * @param array $config Application config + * @param array $additionalHeaders Additional email headers + * @return bool Success status + */ +function sendTemplateEmail($to, $subject, $templateName, $variables, $config, $additionalHeaders = []) { + try { + $message = renderEmailTemplate($templateName, $variables); + + $fromDomain = $config['domain'] ?? ($_SERVER['HTTP_HOST'] ?? 'totalmeet.local'); + $headers = array_merge([ + 'From: noreply@' . $fromDomain, + 'X-Mailer: PHP/' . phpversion(), + 'Content-Type: text/plain; charset=UTF-8' + ], $additionalHeaders); + + return mail($to, $subject, $message, implode("\r\n", $headers)); + } catch (Exception $e) { + error_log("Failed to send template email: " . $e->getMessage()); + return false; + } +}