summaryrefslogtreecommitdiff
path: root/http
diff options
context:
space:
mode:
Diffstat (limited to 'http')
-rw-r--r--http/php/config.php30
-rw-r--r--http/php/mail.php35
2 files changed, 65 insertions, 0 deletions
diff --git a/http/php/config.php b/http/php/config.php
index 6a2d059..9fee39a 100644
--- a/http/php/config.php
+++ b/http/php/config.php
@@ -1,5 +1,35 @@
<?php namespace JoeacNet\Http\Config;
+function localSmtpFrom(): string|null
+{
+ return (string) getenv("LOCAL_SMTP_FROM");
+}
+
+function localSmtpFromName(): string|null
+{
+ return (string) getenv("LOCAL_SMTP_FROM_NAME");
+}
+
+function localSmtpHost(): string|null
+{
+ return (string) getenv("LOCAL_SMTP_HOST");
+}
+
+function localSmtpPort(): string|null
+{
+ return (string) getenv("LOCAL_SMTP_PORT");
+}
+
+function localSmtpUser(): string|null
+{
+ return (string) getenv("LOCAL_SMTP_USER");
+}
+
+function localSmtpPass(): string|null
+{
+ return (string) getenv("LOCAL_SMTP_PASSWORD");
+}
+
function dbScheme(): string|null
{
return (string) getenv("DB_SCHEME");
diff --git a/http/php/mail.php b/http/php/mail.php
new file mode 100644
index 0000000..bd5c377
--- /dev/null
+++ b/http/php/mail.php
@@ -0,0 +1,35 @@
+<?php namespace JoeacNet\Http\Mail;
+
+use PHPMailer\PHPMailer\PHPMailer;
+
+use JoeacNet\Http\Config;
+
+require_once __DIR__ . "/../vendor/autoload.php";
+
+function sendEmail(
+ string $toEmail,
+ string $toName,
+ string $subject,
+ string $body,
+ string $replyToEmail = null,
+ string $replyToName = null,
+): string {
+ $mail = new PHPMailer();
+ $mail->isSMTP();
+ $mail->Host = Config\localSmtpHost();
+ $mail->Port = Config\localSmtpPort();
+ $mail->SMTPAuth = true;
+ $mail->PlainAuth = true;
+ $mail->Username = Config\localSmtpUser();
+ $mail->Password = Config\localSmtpPass();
+ $mail->setFrom(Config\localSmtpFrom(), Config\localSmtpFromName());
+ if (!is_null($replyToEmail)) {
+ $mail->addReplyTo($replyToEmail, $replyToName);
+ }
+ $mail->addAddress($toEmail, $toName);
+ $mail->isHTML(false);
+ $mail->Subject = "joeac.net: $subject";
+ $mail->Body = "$body";
+ $mail->send();
+ return $mail->getLastMessageID();
+}