summaryrefslogtreecommitdiffstats
path: root/app/class/user.class.php
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2017-06-06 12:23:26 -0400
committerMalf Furious <m@lfurio.us>2017-06-19 23:57:39 -0400
commit05c33eb8da0c926c07288ddb07821fb967e20d7d (patch)
tree762a054608cbf280ba090408b1f3206e24422ee7 /app/class/user.class.php
parentfed99e2d0938b10018c8264632165aad56bc2561 (diff)
downloadscrott-05c33eb8da0c926c07288ddb07821fb967e20d7d.tar.gz
scrott-05c33eb8da0c926c07288ddb07821fb967e20d7d.zip
Implement function sendEmail() for user class
Diffstat (limited to 'app/class/user.class.php')
-rw-r--r--app/class/user.class.php39
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();
+ }
}
?>