summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2017-06-06 00:37:04 -0400
committerMalf Furious <m@lfurio.us>2017-06-19 23:57:39 -0400
commit5d43957594589143f0257a918a99b4d6977bdafc (patch)
tree182cc4d924d00f5b2e699ff5795858e4eb69bd65
parenta71aba8c06b829b593b876a53e0c8bff2d343e27 (diff)
downloadscrott-5d43957594589143f0257a918a99b4d6977bdafc.tar.gz
scrott-5d43957594589143f0257a918a99b4d6977bdafc.zip
Add global function sendEmail()
Helper routine to spin up a PHPMailer object, set all its options (mostly from the database) and send off the message.
-rw-r--r--app/class/globals.php34
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();
+}
+
?>