adds mail.php
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user