From 3fea275e10abf8281088e9c7f0ca316df351e41f Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Tue, 6 Jun 2017 01:32:16 -0400 Subject: Update global function sendEmail() Changing the $rcpt argument from an email address string to a user object. This allows us to ensure the address has been confirmed, to not send mail to a blank address, and to include the user's display name in the TO mail headers. Also, added support for mail attachments via PHPMailer. This can be used to forward any attachments added to Scrott message objects to email users as well. --- app/class/globals.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/class/globals.php b/app/class/globals.php index e4285cd..0d4b0ac 100644 --- a/app/class/globals.php +++ b/app/class/globals.php @@ -153,11 +153,19 @@ function saveFile(array $file, string $path, int $maxsize, ?array $allowedMime = * parameters. If config is not established, delivery is * not attempted. Send status (t/f) is returned. */ -function sendEmail(string $subject, string $rcpt, string $mesg) : bool +function sendEmail(string $subject, user $rcpt, string $mesg, + ?string $attachPath = NULL, ?string $attachName = NULL, + bool $overrideEmailConf = false) : bool { if (settings::smtpServer() == "") return false; + if (!$overrideEmailConf && !$rcpt->emailConf) + return true; + + if ($rcpt->email == "") + return true; + $mail = new PHPMailer(); $mail->isSMTP(); $mail->SMTPAuth = true; @@ -168,10 +176,13 @@ function sendEmail(string $subject, string $rcpt, string $mesg) : bool $mail->Port = settings::smtpPort(); $mail->setFrom(settings::smtpEmailAddress()); - $mail->addAddress($rcpt); + $mail->addAddress($rcpt->email, $rcpt->getDisplayName()); $mail->Subject = $subject; $mail->Body = $mesg; + if ($attachPath && $attachName) + $mail->addAttachment($attachPath, $attachName); + return $mail->send(); } -- cgit v1.2.3