diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/class/globals.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/app/class/globals.php b/app/class/globals.php index 615efa6..a84ed39 100644 --- a/app/class/globals.php +++ b/app/class/globals.php @@ -12,6 +12,10 @@ * For more information, please refer to UNLICENSE */ +require_once "class/settings.class.php"; +require_once "class/phpmailer.class.php"; +require_once "class/smtp.class.php"; + /* * This file defines various functions which exist in the global namespace. * These are utility functions and constants for the Scrott application. @@ -144,4 +148,34 @@ function saveFile(array $file, string $path, int $maxsize, ?array $allowedMime = return true; } +/* + * Send an email message using database-stored configuration + * parameters. If config is not established, delivery is + * not attempted. Send status (t/f) is returned. + */ +function sendEmail(string $subject, array $rcpt, string $mesg) : bool +{ + if (settings::smtpServer() == "") + return false; + + $mail = new PHPMailer(); + $mail->isSMTP(); + $mail->SMTPAuth = true; + $mail->Host = settings::smtpServer(); + $mail->Username = settings::smtpUname(); + $mail->Password = settings::smtpPasswd(); + $mail->SMTPSecure = settings::smtpSecurity(); + $mail->Port = settings::smtpPort(); + + $mail->setFrom(settings::smtpEmailAddress()); + + foreach ($rcpt as $to) + $mail->addAddress($to); + + $mail->Subject = $subject; + $mail->Body = $mesg; + + return $mail->send(); +} + ?> |