diff --git a/content/php/confirm.php b/content/php/confirm.php index fb0dc5e..ec92026 100644 --- a/content/php/confirm.php +++ b/content/php/confirm.php @@ -1,25 +1,38 @@ post("lists/$mailingList/members", array( - 'address' => $recipientAddress, - 'name' => $recipientName, - 'description' => 'Form Opt In', - 'subscribed' => true - )); */ + global $db; + echo "ah jup"; + return TRUE; } -require("settings.php"); +require(dirname(__FILE__) . "/settings.php"); $c = isset($_GET['c']) ? SanitizeInputs($_GET['c']) : NULL; $e = isset($_GET['e']) ? SanitizeInputs($_GET['e']) : NULL; -if (isset($c) && isset($e) && CheckConfirmationHash($e, $c) && AddMemberToDB($e)) { - header('Location: /newsletter/confirmed.html'); +if (! (isset($c) && isset($e) && CheckConfirmationHash($e, $c)) ) { + header($statusCode); + header("Location: " . $errorURL . "?" . http_build_query(["msg" => SanitizeInputs("Ungültiger Link")])); } else { - header('Location: /newsletter/confirm-error.html') + $result = AddMemberToDB($e); + if ($result == TRUE) { + header($statusCode); + header("Location: " . $successURL); + } elseif (gettype($result == "string")) { + header($statusCode); + header("Location: " . $errorURL . "?" . http_build_query(["msg" => SanitizeInputs($result)])); + } else { + header($statusCode); + header("Location: " . $errorURL . "?" . http_build_query(["msg" => SanitizeInputs("Unbekannter Fehler")])); + } } ?> \ No newline at end of file diff --git a/content/php/settings.php b/content/php/settings.php index 61eca0c..f9a49d3 100644 --- a/content/php/settings.php +++ b/content/php/settings.php @@ -1,13 +1,50 @@ 'tobias-radloff.de', + "domain" => 'localhost', + "uniqueKey" => '***REMOVED***', // works like password salt + "confirmScript" => "/confirm.php" +); +$general["siteURL"] = "https://" . $general["domain"]; + +// smtp info +$smtp = array( + "host" => '***REMOVED*** + "port" => 587, + "username" => 'tobias', + "password" => '***REMOVED***', + "auth" => TRUE, + "fromAddress" => "***REMOVED***", // 'newsletter@tobias-radloff.de' + "fromName" => "Tobias Radloffs Newsletter", +); + +$body = array( + "Hallo!", + "Bitte bestätige die Anmeldung für meinen Newsletter, indem du auf den folgenden Link klickst:", + "%confirmURL%", // placeholder + "Bis bald und viele Grüße, Tobias" +); + +// mail contents +$mail = array( + "subject" => 'Newsletter-Anmeldung bestaetigen', + "bodyHTML" => "
" . implode("
", $body) . "
", + "bodyText" => implode("\n\n", $body) +); + +// DB constants +$db = array( + "host" => "", + "port" => "", + "username" => "", + "password" => "" +); function SanitizeInputs($var) { - return = htmlspecialchars($var, ENT_QUOTES); + return htmlspecialchars($var, ENT_QUOTES); } function SanitizeEmail ($var) { @@ -19,6 +56,7 @@ function SanitizeEmail ($var) { } function CheckConfirmationHash($confEmail, $confCode) { - return (md5($confEmail . $uniqueKey) === $confCode); + global $general; + return (md5($confEmail . $general["uniqueKey"]) === $confCode); } ?> \ No newline at end of file diff --git a/content/php/subscribe.php b/content/php/subscribe.php index b9a853e..017ee64 100644 --- a/content/php/subscribe.php +++ b/content/php/subscribe.php @@ -1,37 +1,73 @@ $hashedUnique, "e" => $recipientAddress]); + $confirmURL = $general["siteURL"] . $general["confirmScript"] . "?" . $confirmQuery; - // FIXME - // use PHPMailer? - $to = $recipientAddress; - $subject = 'Newsletter-Anmeldung bestaetigen'; - $body = 'Hallo! Bitte bestätige die Anmeldung für meinen Newsletter, indem du auf diesen Link klickst. Viel Spaß mit dem Gedicht!
Bis bald und viele Grüße
Tobias';
- $headers = 'From: newsletter@' . $domain;
- $result = mail($to, $subject, $body, $headers);
- return $result;
+ // create PHPMailer instance
+ $mailer = new PHPMailer(true);
+
+ try {
+ //Server settings
+// $mailer->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
+ $mailer->isSMTP();
+ $mailer->Host = $smtp["host"];
+ $mailer->SMTPAuth = $smtp["auth"];
+ $mailer->Username = $smtp["username"];
+ $mailer->Password = $smtp["password"];
+ //$mailer->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
+ $mailer->Port = $smtp["port"]; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
+
+ //Recipients
+ $mailer->setFrom($smtp["fromAddress"], $smtp["fromName"]);
+ $mailer->addAddress($recipientAddress); //Add a recipient
+
+ //Content
+ $mailer->CharSet = "UTF-8";
+ $mailer->isHTML(true);
+ $mailer->Subject = $mail["subject"];
+ $mailer->Body = str_replace("%confirmURL%", $confirmURL, $mail["bodyHTML"]);
+ $mailer->AltBody = str_replace("%confirmURL%", $confirmURL, $mail["bodyText"]);
+
+ $mailer->send();
+ return TRUE;
+ } catch (Exception $e) {
+ error_log("Message error: " . $e);
+ return FALSE;
+ }
}
-require("settings.php");
+require($dname . "/settings.php");
if (isset($_POST['email'])) {
$email = SanitizeEmail(trim($_POST['email']));
- echo $email; //DEBUG
+// error_log("Received subscription request for address " . $email . " ..."); //DEBUG
$result = SendConfirmationEmail($email);
- if $result == TRUE ) {
+ if ( $result == TRUE ) {
header('Location: /newsletter/subscribed.html');
+ error_log("Message to " . $email . " has been sent.");
} else {
- header('Location: /newsletter/subscribe-error.html')
+ header('Location: /newsletter/subscribe-error.html');
+ error_log("Message to " . $email . " could not be sent.");
}
}
?>
\ No newline at end of file
diff --git a/content/php/unsubscribe.php b/content/php/unsubscribe.php
index 5f3c4fa..aed68e0 100644
--- a/content/php/unsubscribe.php
+++ b/content/php/unsubscribe.php
@@ -1,18 +1,18 @@
\ No newline at end of file
diff --git a/theme/templates/includes/unsubscribe.html b/theme/templates/includes/unsubscribe.html
index 551a527..f8efb8f 100644
--- a/theme/templates/includes/unsubscribe.html
+++ b/theme/templates/includes/unsubscribe.html
@@ -3,6 +3,6 @@
Komm gerne wieder, irgendwann.