small changes

This commit is contained in:
eclipse 2025-03-04 23:10:53 +01:00
parent 5e735d6a9a
commit 9e9c1cb562
4 changed files with 43 additions and 15 deletions

View File

@ -1,18 +1,19 @@
<?php <?php
// inspired by https://www.mailgun.com/blog/email/double-opt-in-with-php-mailgun/ // inspired by https://www.mailgun.com/blog/email/double-opt-in-with-php-mailgun/
require(dirname(__FILE__) . '/settings.php'); require(dirname(__FILE__) . '/../settings.php');
$successURL = '/newsletter/confirmed.html'; $successURL = '/confirmed.html';
$errorURL = '/newsletter/error.html'; $errorURL = '/error.html';
$err = 'Bestätigung fehlgeschlagen'; $err = 'Bestätigung fehlgeschlagen';
// Adds new subscriber to database. Returns an error message on failure, TRUE on success. // Adds new subscriber to database. Returns an error message on failure, TRUE on success.
function AddSubscriberToDB($subscriberAddress, $subscriberName = NULL) { function AddSubscriberToDB($subscriberAddress, $subscriberName = NULL) {
$pdo = getPDO(); $pdo = getPDO();
// check if record exists // check if record exists
$check = NotAlreadySubscribed($subscriberAddress, $pdo); $check = NotYetSubscribed($subscriberAddress, $pdo);
if ( gettype($check) == 'string' ) { if ( gettype($check) == 'string' ) {
return $check; return $check;
} }

View File

@ -1,12 +1,29 @@
<?php <?php
// inspired by https://www.mailgun.com/blog/email/double-opt-in-with-php-mailgun/ // inspired by https://www.mailgun.com/blog/email/double-opt-in-with-php-mailgun/
require(dirname(__FILE__) . '/settings.php'); require(dirname(__FILE__) . '/../settings.php');
$successURL = '/newsletter/success.html'; $successURL = '/success.html';
$errorURL = '/newsletter/error.html'; $errorURL = '/error.html';
$err = 'Anmeldung fehlgeschlagen'; $err = 'Anmeldung fehlgeschlagen';
// body template for confirmation email
$bodyConfirmation = [
'Hallo!',
'Bitte bestätige die Anmeldung für meinen Newsletter, indem du auf den folgenden Link klickst:',
'%Placeholder%',
'Bis bald und viele Grüße, Tobias'
];
// contents of confirmation email
$mailConfirmation = [
'subject' => 'Newsletter-Anmeldung bestaetigen',
'bodyHTML' => '<p>' . implode('</p><p>', $bodyConfirmation) . '</p>',
'bodyText' => implode("\n\n", $bodyConfirmation),
'fromAddress' => '***REMOVED***', // 'newsletter@tobias-radloff.de'
'fromName' => 'Tobias Radloffs Newsletter'
];
// check if email parameter is set // check if email parameter is set
if ( ! isset($_POST['email']) ) { if ( ! isset($_POST['email']) ) {
GracefulExit($errorURL, "{$err}: Keine Emailadresse angegeben."); GracefulExit($errorURL, "{$err}: Keine Emailadresse angegeben.");
@ -20,7 +37,7 @@ if ( ! filter_var($email, FILTER_VALIDATE_EMAIL)) {
// check whether address is already subscribed // check whether address is already subscribed
try { try {
$check = NotAlreadySubscribed($email); $check = NotYetSubscribed($email);
if ( gettype($check) == 'string' ) { if ( gettype($check) == 'string' ) {
GracefulExit($errorURL, "{$err}: {$check}."); GracefulExit($errorURL, "{$err}: {$check}.");
} }
@ -28,11 +45,15 @@ try {
GracefulExit($errorURL, "{$err}: {$e->getMessage()}"); GracefulExit($errorURL, "{$err}: {$e->getMessage()}");
} }
// send email with confirmation link // build and add link to
$confirmQuery = http_build_query(['c' => GetConfirmationHash($email), 'e' => $email]); $confirmQuery = http_build_query(['c' => GetConfirmationHash($email), 'e' => $email]);
$confirmLink = $general['siteURL'] . $general['confirmScript'] . "?" . $confirmQuery; $confirmLink = $general['siteURL'] . $general['confirmScript'] . "?" . $confirmQuery;
$mailConfirmation['bodyHTML'] = str_replace('%Placeholder%', $confirmLink, $mailConfirmation['bodyHTML']);
$mailConfirmation['bodyText'] = str_replace('%Placeholder%', $confirmLink, $mailConfirmation['bodyText']);
// send email
try { try {
SendEmail($email, $mailConfirmation, $confirmLink); SendEmail($email, $mailConfirmation);
} catch (Exception $e) { } catch (Exception $e) {
GracefulExit($errorURL, "{$err}: {$e->getMessage()}"); GracefulExit($errorURL, "{$err}: {$e->getMessage()}");
} }

View File

@ -1,17 +1,19 @@
<?php <?php
require(dirname(__FILE__) . '/settings.php'); require(dirname(__FILE__) . '/../settings.php');
$successURL = '/newsletter/success.html'; $successURL = '/success.html';
$errorURL = '/newsletter/error.html'; $errorURL = '/error.html';
$err = "Abmeldung fehlgeschlagen"; $err = "Abmeldung fehlgeschlagen";
function RemoveSubscriberFromDB($subscriberAddress) { function RemoveSubscriberFromDB($subscriberAddress) {
$pdo = getPDO(); $pdo = getPDO();
// make sure record exists // make sure record exists
$check = NotAlreadySubscribed($subscriberAddress, $pdo); $check = NotYetSubscribed($subscriberAddress, $pdo);
if ( gettype($check) == 'string' ) { if ( gettype($check) == 'boolean' ) {
return "Emailadresse {$subscriberAddress} ist unbekannt";
} elseif ( gettype($check) == 'string' and $check != "Emailadresse {$subscriberAddress} ist bereits eingetragen") {
return $check; return $check;
} }
@ -45,4 +47,7 @@ try {
} catch(\PDOException $e) { } catch(\PDOException $e) {
GracefulExit($error, "{$err}: {$e->getMessage()}"); GracefulExit($error, "{$err}: {$e->getMessage()}");
} }
// success
GracefulExit($successURL, 'Abmeldung erfolgt: Emailadresse ist aus dem Newsletter ausgetragen');
?> ?>

View File

@ -356,6 +356,7 @@ pre {
.card-body img { .card-body img {
height: var(--card-height); height: var(--card-height);
object-fit: contain;
} }