From 74be45851ec249a65b5be77a5b7cd36754d05b39 Mon Sep 17 00:00:00 2001 From: eclipse Date: Wed, 5 Mar 2025 00:18:41 +0100 Subject: [PATCH] added notification emails for newsletter confirmation and unsubscription --- content/pages/danke.md | 79 ++++++++++++++++++------------------- content/pages/success.md | 6 +-- content/php/confirm.php | 14 +++++-- content/php/contact.php | 2 +- content/php/settings.php | 3 +- content/php/subscribe.php | 14 +++---- content/php/unsubscribe.php | 11 ++++++ 7 files changed, 73 insertions(+), 56 deletions(-) diff --git a/content/pages/danke.md b/content/pages/danke.md index 9cdd046..d8f3467 100644 --- a/content/pages/danke.md +++ b/content/pages/danke.md @@ -1,49 +1,48 @@ --- -title: Nachricht versandt +title: Kleines Dankeschön date: 2025-02-04 10:20 author: Tobias Radloff summary: Danke für deine Nachricht. lang: de slug: danke -save_as: kontakt/danke/index.html -url: kontakt/danke/ +save_as: newsletter/danke.html --- -Danke für deine Nachricht. Ich antworte bestimmt bald. Und bis es soweit ist, kannst du dich an diesem Gedicht von mir erfreuen :-) +Klasse, dass du dich für meinen Newsletter angemeldet hast. Als kleines Dankeschön und um die Wartezeit auf die nächste Ausgabe zu verkürzen, ist hier ein bislang unveröffentlichtes Gedicht von mir. Viel Spaß :-) -## Handwerk - -Dichter, Autor, Mann der Worte -so werd ich genannt -doch nicht nur mein Geist ist fleißig, -nein, auch meine Hand. - -Vor Schmutz unter den Fingernägeln -schreck ich nicht zurück -ein echter Mann wie ich, der hat -handwerkliches Geschick. - -Ich freu mich, wenn es gilt, ein Löch- -lein in die Wand zu bohr'n -denn jedes Mal treff ich mit Verve -genau ins Wasserrohr. - -Die Muttern an den Autorädern -zieh ich selber nach -klemm' mir dabei den Ischias -und lieg' drei Wochen flach. - -Ich bau IKEA-Möbel auf -die Schwerkraft baut sie ab -beim Umzug helf ich freudig mit -und mach als erster schlapp. - -Die Waschmaschine ist kaputt? -Ich kümmere mich drum -wofür, wenn nicht für Wasserschäden, -gibt's Versicherung'n? - -Doch neuerdings werd ich nicht mehr -gefragt in Handwerksfragen -So bleibt mir nur ein Handwerk noch: -Gedichte aufzusagen. \ No newline at end of file +> ## Handwerk +> +> Dichter, Autor, Mann der Worte +> so werd ich genannt +> doch nicht nur mein Geist ist fleißig, +> nein, auch meine Hand. +> +> Vor Schmutz unter den Fingernägeln +> schreck ich nicht zurück +> ein echter Mann wie ich, der hat +> handwerkliches Geschick. +> +> Ich freu mich, wenn es gilt, ein Löch- +> lein in die Wand zu bohr'n +> denn jedes Mal treff ich mit Verve +> genau ins Wasserrohr. +> +> Die Muttern an den Autorädern +> zieh ich selber nach +> klemm' mir dabei den Ischias +> und lieg' drei Wochen flach. +> +> Ich bau IKEA-Möbel auf +> die Schwerkraft baut sie ab +> beim Umzug helf ich freudig mit +> und mach als erster schlapp. +> +> Die Waschmaschine ist kaputt? +> Ich kümmere mich drum +> wofür, wenn nicht für Wasserschäden, +> gibt's Versicherung'n? +> +> Doch neuerdings werd ich nicht mehr +> gefragt in Handwerksfragen +> So bleibt mir nur ein Handwerk noch: +> Gedichte aufzusagen. \ No newline at end of file diff --git a/content/pages/success.md b/content/pages/success.md index 05d3f05..a00e419 100644 --- a/content/pages/success.md +++ b/content/pages/success.md @@ -1,8 +1,8 @@ --- -title: "Das lief richtig gut :-)" +title: "Das hat geklappt" date: 2025-03-04 23:19 author: Tobias Radloff -summary: Erfolg auf der ganzen Linie +summary: Ein Arbeitsschritt wurde erfolgreich bewältigt. lang: de slug: success save_as: success.html @@ -12,8 +12,6 @@ featured_image: credit: Ian Stauffer on Unsplash.com --- -Na, das lief doch mal richtig gut. Erfolg auf der ganzen Linie, würde ich sagen. So soll es sein, und so bleibt es hoffentlich auch. - [← zur Startseite](/) diff --git a/content/php/confirm.php b/content/php/confirm.php index 834bc84..c99fc4a 100644 --- a/content/php/confirm.php +++ b/content/php/confirm.php @@ -3,10 +3,17 @@ require(dirname(__FILE__) . '/../settings.php'); -$successURL = '/confirmed.html'; +$successURL = '/newsletter/danke.html'; $errorURL = '/error.html'; $err = 'Bestätigung fehlgeschlagen'; +// contents of notification email +$mailContents = [ + 'subject' => 'Neuer Newsletter-Abonnent', + 'bodyText' => "Jemand hat seine Emailadresse für den Empfang des Newsletters bestätigt:\n\n%Placeholder%", + 'fromAddress' => '***REMOVED***', // 'newsletter@tobias-radloff.de' + 'fromName' => 'Tobias Radloff' +]; // Adds new subscriber to database. Returns an error message on failure, TRUE on success. function AddSubscriberToDB($subscriberAddress, $subscriberName = NULL) { @@ -22,7 +29,6 @@ function AddSubscriberToDB($subscriberAddress, $subscriberName = NULL) { global $general; $query = $pdo->prepare($general['sql']['create_record']); if ( ( ! $query->execute([':e' => $subscriberAddress, ':n' => $subscriberName]) ) or ( $query->fetch() ) ) { -// error_log("Datenbankfehler: Einfügen von Emailadresse {$subscriberAddress} ergab einen Fehler."); return 'Fehler beim Eintragen in die Datenbank'; } return TRUE; @@ -52,5 +58,7 @@ try { } // success -GracefulExit($successURL, 'Bestätigung erfolgt: Newsletter-Anmeldung bestätigt'); +$mailContents['bodyText'] = str_replace('%Placeholder%', $e, $mailContents['bodyText']); +SendEmail($general['notificationAddress'], $mailContents); +GracefulExit($successURL); ?> \ No newline at end of file diff --git a/content/php/contact.php b/content/php/contact.php index 49bdaca..047e2ea 100644 --- a/content/php/contact.php +++ b/content/php/contact.php @@ -27,7 +27,7 @@ $mailContents = [ ]; try { - sendEmail($_POST['email'], $mailContents); + SendEmail($_POST['email'], $mailContents); } catch (Exception $e) { GracefulExit($errorURL, "{$err}: {$e->getMessage()}"); } diff --git a/content/php/settings.php b/content/php/settings.php index 2859017..84f1ff4 100644 --- a/content/php/settings.php +++ b/content/php/settings.php @@ -27,7 +27,8 @@ $general = [ 'read_record' => 'SELECT 1 FROM subscribers WHERE email = :e;', 'update_record' => '', 'delete_record' => 'DELETE FROM subscribers WHERE email = :e;' - ] + ], + 'notificationAddress' => 'webseite@tobias-radloff.de' ]; // complete site URL $general['siteURL'] = 'https://' . $general['domain']; diff --git a/content/php/subscribe.php b/content/php/subscribe.php index 43940a3..1bc888a 100644 --- a/content/php/subscribe.php +++ b/content/php/subscribe.php @@ -8,7 +8,7 @@ $errorURL = '/error.html'; $err = 'Anmeldung fehlgeschlagen'; // body template for confirmation email -$bodyConfirmation = [ +$body = [ 'Hallo!', 'Bitte bestätige die Anmeldung für meinen Newsletter, indem du auf den folgenden Link klickst:', '%Placeholder%', @@ -16,10 +16,10 @@ $bodyConfirmation = [ ]; // contents of confirmation email -$mailConfirmation = [ +$mailContents = [ 'subject' => 'Newsletter-Anmeldung bestaetigen', - 'bodyHTML' => '

' . implode('

', $bodyConfirmation) . '

', - 'bodyText' => implode("\n\n", $bodyConfirmation), + 'bodyHTML' => '

' . implode('

', $body) . '

', + 'bodyText' => implode("\n\n", $body), 'fromAddress' => '***REMOVED***', // 'newsletter@tobias-radloff.de' 'fromName' => 'Tobias Radloffs Newsletter' ]; @@ -48,12 +48,12 @@ try { // build and add link to $confirmQuery = http_build_query(['c' => GetConfirmationHash($email), 'e' => $email]); $confirmLink = $general['siteURL'] . $general['confirmScript'] . "?" . $confirmQuery; -$mailConfirmation['bodyHTML'] = str_replace('%Placeholder%', $confirmLink, $mailConfirmation['bodyHTML']); -$mailConfirmation['bodyText'] = str_replace('%Placeholder%', $confirmLink, $mailConfirmation['bodyText']); +$mailContents['bodyHTML'] = str_replace('%Placeholder%', $confirmLink, $mailContents['bodyHTML']); +$mailContents['bodyText'] = str_replace('%Placeholder%', $confirmLink, $mailContents['bodyText']); // send email try { - SendEmail($email, $mailConfirmation); + SendEmail($email, $mailContents); } catch (Exception $e) { GracefulExit($errorURL, "{$err}: {$e->getMessage()}"); } diff --git a/content/php/unsubscribe.php b/content/php/unsubscribe.php index a247062..1aa2090 100644 --- a/content/php/unsubscribe.php +++ b/content/php/unsubscribe.php @@ -6,6 +6,15 @@ $successURL = '/success.html'; $errorURL = '/error.html'; $err = "Abmeldung fehlgeschlagen"; +// contents of notification email +$mailContents = [ + 'subject' => 'Ein Newsletter-Abonnent weniger', + 'bodyText' => "Jemand hat sich vom Newsletter abgemeldet:\n\n%Placeholder%", + 'fromAddress' => '***REMOVED***', // 'newsletter@tobias-radloff.de' + 'fromName' => 'Tobias Radloff' +]; + + function RemoveSubscriberFromDB($subscriberAddress) { $pdo = getPDO(); @@ -49,5 +58,7 @@ try { } // success +$mailContents['bodyText'] = str_replace('%Placeholder%', $e, $mailContents['bodyText']); +SendEmail($general['notificationAddress'], $mailContents); GracefulExit($successURL, 'Abmeldung erfolgt: Emailadresse ist aus dem Newsletter ausgetragen'); ?> \ No newline at end of file