t-r.de/content/php/settings.php

104 lines
3.0 KiB
PHP

<?php
// import PHPMailer classes into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
$dname = dirname(__FILE__);
require $dname . '/Exception.php';
require $dname . '/PHPMailer.php';
require $dname . '/SMTP.php';
// general constants
$general = [
// 'domain' => 'tobias-radloff.de',
'domain' => 'localhost',
'uniqueKey' => '***REMOVED***', // works like password salt
'confirmScript' => '/confirm.php',
'statusCode' => 'HTTP/1.1 303 See Other'
];
$general['siteURL'] = 'https://' . $general['domain'];
// smtp info
$smtp = [
'host' => '***REMOVED***
'port' => 587,
'username' => 'tobias',
'password' => '***REMOVED***',
'auth' => TRUE,
'fromAddress' => '***REMOVED***', // 'newsletter@tobias-radloff.de'
'fromName' => 'Tobias Radloffs Newsletter',
];
$bodyConfirmation = [
'Hallo!',
'Bitte bestätige die Anmeldung für meinen Newsletter, indem du auf den folgenden Link klickst:',
'%Placeholder%', // placeholder
'Bis bald und viele Grüße, Tobias'
];
// mail contents
$mailConfirmation = [
'subject' => 'Newsletter-Anmeldung bestaetigen',
'bodyHTML' => '<p>' . implode('</p><p>', $bodyConfirmation) . '</p>',
'bodyText' => implode("\n\n", $bodyConfirmation)
];
// DB constants
$db = [
'host' => '',
'port' => '',
'username' => '',
'password' => ''
];
function SendEmail($recipientAddress, $mailContents, $link = NULL) {
global $general, $smtp;
$mail = new PHPMailer(true);
try {
//Server settings
// $mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail->isSMTP();
$mail->Host = $smtp["host"];
$mail->SMTPAuth = $smtp["auth"];
$mail->Username = $smtp["username"];
$mail->Password = $smtp["password"];
//$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail->Port = $smtp["port"]; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Recipients
$mail->setFrom($smtp["fromAddress"], $smtp["fromName"]);
$mail->addAddress($recipientAddress); //Add a recipient
//Content
if (isset($link)) {
$mailContents["bodyHTML"] = str_replace("%Placeholder%", $link, $mailContents["bodyHTML"]);
$mailContents["bodyText"] = str_replace("%Placeholder%", $link, $mailContents["bodyText"]);
}
$mail->CharSet = "UTF-8";
$mail->isHTML(true);
$mail->Subject = $mailContents["subject"];
$mail->Body = $mailContents["bodyHTML"];
$mail->AltBody = $mailContents["bodyText"];
$mail->send();
return TRUE;
} catch (Exception $e) {
error_log("Message error: {$e}");
return FALSE;
}
}
function GracefulExit($location, $message = NULL) {
global $general;
header($general['statusCode']);
if (isset($message)) {
$location .= "?" . http_build_query(['msg' => $message]);
error_log($location);
}
header("Location: {$location}");
}
?>