diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/class/user.class.php | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/app/class/user.class.php b/app/class/user.class.php index a6addf6..01552f6 100644 --- a/app/class/user.class.php +++ b/app/class/user.class.php @@ -282,6 +282,45 @@ class user extends agent return $groups; } + + /* + * Send an email message to this user using stored configuration + * parameters. If config is not established, delivery is not + * attempted. Return status. + */ + public function sendEmail(string $subj, string $mesg, + ?string $attachPath = NULL, ?string $attachName = NULL, + bool $ignoreEmailConf = false) : bool + { + if (settings::smtpServer() == "") + return false; + + if (!$ignoreEmailConf && !$this->emailConf) + return true; + + if ($this->email == "") + return true; + + $mail = new PHPMailer(); + $mail->isSMTP(); + $mail->SMTPAuth = true; + + $mail->Host = settings::smtpServer(); + $mail->Port = settings::smtpPort(); + $mail->Username = settings::smtpUname(); + $mail->Password = settings::smtpPasswd(); + $mail->SMTPSecure = settings::smtpSecurity(); + + $mail->setFrom(settings::smtpEmailAddress()); + $mail->addAddress($this->email, $this->getDisplayName()); + $mail->Subject = $subj; + $mail->Body = $mesg; + + if ($attachPath && $attachName) + $mail->addAttachment($attachPath, $attachName); + + return $mail->send(); + } } ?> |