diff --git a/content/pages/error.md b/content/pages/error.md index 228a341..a2744f7 100644 --- a/content/pages/error.md +++ b/content/pages/error.md @@ -4,11 +4,9 @@ date: 2025-03-03 17:19 author: Tobias Radloff summary: Ein Fehler ist aufgetreten lang: de -slug: error -save_as: newsletter/error.html -url: newsletter/error.html +save_as: error.html featured_image: - - pic: ../images/newsletter/error-unsplash.jpg + - pic: ../images/error-unsplash.jpg alt: eine Frau vor einem Laptop stützt geknickt den Kopf in die Hände credit: Elisa Ventur on Unsplash.com --- diff --git a/content/php/contact.php b/content/php/contact.php index 1f54f83..49bdaca 100644 --- a/content/php/contact.php +++ b/content/php/contact.php @@ -1,18 +1,37 @@ 'Diese Nachricht kam ueber das Kontaktformular von t-r.de', + 'bodyText' => implode("\n\n", $body), + 'fromAddress' => '***REMOVED***', //'kontakt@tobias-radloff.de', + 'fromName' => 'Tobias Radloffs Kontaktformular' +]; + +try { + sendEmail($_POST['email'], $mailContents); +} catch (Exception $e) { + GracefulExit($errorURL, "{$err}: {$e->getMessage()}"); +} + +header("Location: {$successURL}"); ?> + diff --git a/content/php/settings.php b/content/php/settings.php index d4215e6..2859017 100644 --- a/content/php/settings.php +++ b/content/php/settings.php @@ -5,9 +5,9 @@ use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; $dname = dirname(__FILE__); -require $dname . '/../Exception.php'; -require $dname . '/../PHPMailer.php'; -require $dname . '/../SMTP.php'; +require $dname . '/Exception.php'; +require $dname . '/PHPMailer.php'; +require $dname . '/SMTP.php'; // general constants $general = [ @@ -39,23 +39,6 @@ $smtp = [ 'username' => 'tobias', 'password' => '***REMOVED***', 'auth' => TRUE, - 'fromAddress' => '***REMOVED***', // 'newsletter@tobias-radloff.de' - 'fromName' => 'Tobias Radloffs Newsletter', -]; - -// body of 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' => '
' . implode('
', $bodyConfirmation) . '
', - 'bodyText' => implode("\n\n", $bodyConfirmation) ]; // database information @@ -83,36 +66,38 @@ function getPDO($dbType = 'sqlite') { return new \PDO($db[$dbType]['dsn']); } -// Sends an email to single recipient with subject and body specified in an array -function SendEmail($recipientAddress, $mailContents, $link = NULL) { +// Sends an email to single recipient with subject, body and sender info specified in an array +function SendEmail($recipientAddress, $mailContents) { global $general, $smtp; $mail = new PHPMailer(true); //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->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` + $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"]); + // recipient $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"]); + // content + $mail->CharSet = 'UTF-8'; + if ( isset($mailContents['bodyHTML']) and $mailContents['bodyHTML'] != '' ) { + $mail->isHTML(true); + $mail->Body = $mailContents['bodyHTML']; + $mail->AltBody = $mailContents['bodyText']; + } else { + $mail->isHTML(false); + $mail->Body = $mailContents['bodyText']; } - $mail->CharSet = "UTF-8"; - $mail->isHTML(true); - $mail->Subject = $mailContents["subject"]; - $mail->Body = $mailContents["bodyHTML"]; - $mail->AltBody = $mailContents["bodyText"]; + $mail->Subject = $mailContents['subject']; + $mail->setFrom($mailContents['fromAddress'], $mailContents['fromName']); + // send $mail->send(); } @@ -121,33 +106,29 @@ function MakeSureTableExists($pdo) { global $general; $query = $pdo->prepare($general['sql']['create_table']); if ( ! $query->execute() ) { -// error_log('Unbekannter Datenbankfehler beim Prüfen/Erzeugen der Tabelle.'); - return "Unbekannter Datenbankfehler"; + return 'Unbekannter Datenbankfehler'; } return TRUE; } // returns true if record does not yet exist in database; error string otherwise -function NotAlreadySubscribed($email, $pdo = NULL) { +function NotYetSubscribed($email, $pdo = NULL) { if (!isset($pdo)) { $pdo = getPDO(); } $result = MakeSureTableExists($pdo); - if ( gettype($result) == "string" ) { -// error_log("Datenbankfehler beim Adresscheck: {$result}"); + if ( gettype($result) == 'string' ) { return $result; } global $general; $query = $pdo->prepare($general['sql']['read_record']); if ( ! $query->execute([':e' => $email]) ) { -// error_log("Datenbankfehler: Adresscheck für Emailadresse {$email} ergab einen Fehler."); - return "Fehler beim Zugriff auf Datenbank"; + return 'Fehler beim Zugriff auf Datenbank'; } if ( $query->fetch() ) { -// error_log("Adresscheck: Emailadresse {$email} ist bereits eingetragen."); return "Emailadresse {$email} ist bereits eingetragen"; } @@ -155,13 +136,14 @@ function NotAlreadySubscribed($email, $pdo = NULL) { return TRUE; } + // redirects to specified URL via GET request and conveys an optional message; then exits function GracefulExit($location, $message = NULL) { global $general; header($general['statusCode']); if (isset($message)) { - $location .= "?" . http_build_query(['msg' => $message]); - error_log($location); + $location .= '?' . http_build_query(['msg' => $message]); + error_log("Redirecting to {$location} now …"); } header("Location: {$location}"); exit; diff --git a/pelicanconf.py b/pelicanconf.py index eb8953b..00740d5 100644 --- a/pelicanconf.py +++ b/pelicanconf.py @@ -21,13 +21,14 @@ PATH = "content" ARTICLE_PATHS = ["posts"] PAGE_PATHS = ["pages"] STATIC_PATHS = ["images", "favicon", "php"] +# TEMPLATE_PAGES = { 'templates/cform.html': 'cform.html', } DIRECT_TEMPLATES = ['index', 'tags'] IGNORE_FILES = ['**/.*', '__pycache__', 'favicon-from-svg.sh', '*.metadata'] EXTRA_PATH_METADATA = { 'favicon/favicon.ico': {'path': 'favicon.ico'}, - 'php/settings.php': {'path': 'newsletter/settings.php'}, + 'php/settings.php': {'path': 'settings.php'}, 'php/subscribe.php': {'path': 'newsletter/subscribe.php'}, 'php/confirm.php': {'path': 'newsletter/confirm.php'}, 'php/unsubscribe.php': {'path': 'newsletter/unsubscribe.php'}, @@ -123,5 +124,5 @@ JINJA_ENVIRONMENT = { "extensions": ["jinja2.ext.debug", "jinja2.ext.do"] } # Self-defined Settings # ############################################################################### -STYLESHEET_FILES = ("pico.amber.css", "custom.css") +STYLESHEET_FILES = ("pico.zinc.css", "custom.css") DEFAULT_METADESC = "Tobias Radloff ist preisgekrönter Schriftsteller von Romanen, Kurzgeschichten und Lyrik auf deutsch und englisch. Zu seinen Genres gehören Fantasy, SF, Krimi, Kinder-/Jugendbuch und mehr. Er organisiert und moderiert die regelmäßigen Lesereihen 'Potsdams andere Welten' und 'Babelsberger Lesesalon'." \ No newline at end of file