summaryrefslogtreecommitdiffstats
path: root/app/class
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2017-06-06 01:32:16 -0400
committerMalf Furious <m@lfurio.us>2017-06-19 23:57:39 -0400
commit3fea275e10abf8281088e9c7f0ca316df351e41f (patch)
tree9fc193a53b2e4f7685c0d27b97d26e9f5befa2bc /app/class
parent4211ae67018059407830e60ec4199c80320b6dc3 (diff)
downloadscrott-3fea275e10abf8281088e9c7f0ca316df351e41f.tar.gz
scrott-3fea275e10abf8281088e9c7f0ca316df351e41f.zip
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.
Diffstat (limited to 'app/class')
-rw-r--r--app/class/globals.php15
1 files changed, 13 insertions, 2 deletions
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();
}