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

37 lines
1.2 KiB
PHP

<?php
// inspired by https://www.mailgun.com/blog/email/double-opt-in-with-php-mailgun/
function MakeConfirmationHash($confEmail, $confCode) {
return md5($confEmail . $confCode);
}
function SendConfirmationEmail($recipientAddress) {
global $domain, $fromAddress, $siteURL, $uniqueKey;
$hashedUnique = MakeConfirmationHash($recipientAddress, $uniqueKey);
$confirmURL = $siteURL . '/confirm.php?c=' . $hashedUnique . '&e=' . $recipientAddress
// FIXME
// use PHPMailer?
$to = $recipientAddress;
$subject = 'Newsletter-Anmeldung bestaetigen';
$body = '<p>Hallo! Bitte bestätige die Anmeldung für meinen Newsletter, indem du auf <a href="' . $confirmURL . '">diesen Link</a> klickst. Viel Spaß mit dem Gedicht!</p><p>Bis bald und viele Grüße<br>Tobias';
$headers = 'From: newsletter@' . $domain;
$result = mail($to, $subject, $body, $headers);
return $result;
}
require("settings.php");
if (isset($_POST['email'])) {
$email = SanitizeEmail(trim($_POST['email']));
echo $email; //DEBUG
$result = SendConfirmationEmail($email);
if $result == TRUE ) {
header('Location: /newsletter/subscribed.html');
} else {
header('Location: /newsletter/subscribe-error.html')
}
}
?>