42 lines
1.4 KiB
PHP
42 lines
1.4 KiB
PHP
<?php
|
|
// inspired by https://www.mailgun.com/blog/email/double-opt-in-with-php-mailgun/
|
|
|
|
require(dirname(__FILE__) . '/settings.php');
|
|
|
|
$successURL = '/newsletter/success.html';
|
|
$errorURL = '/newsletter/error.html';
|
|
$err = 'Anmeldung fehlgeschlagen';
|
|
|
|
// check if email parameter is set
|
|
if ( ! isset($_POST['email']) ) {
|
|
GracefulExit($errorURL, "{$err}: Keine Emailadresse angegeben.");
|
|
}
|
|
|
|
// check if it's a well-formed email address
|
|
$email = filter_var(trim($_POST['email'], FILTER_SANITIZE_STRING));
|
|
if ( ! filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
GracefulExit($errorURL, "{$err}: Ungültige Emailadresse {$email}");
|
|
}
|
|
|
|
// check whether address is already subscribed
|
|
try {
|
|
$check = NotAlreadySubscribed($email);
|
|
if ( gettype($check) == 'string' ) {
|
|
GracefulExit($errorURL, "{$err}: {$check}.");
|
|
}
|
|
} catch (\PDOException $e) {
|
|
GracefulExit($errorURL, "{$err}: {$e->getMessage()}");
|
|
}
|
|
|
|
// send email with confirmation link
|
|
$confirmQuery = http_build_query(['c' => GetConfirmationHash($email), 'e' => $email]);
|
|
$confirmLink = $general['siteURL'] . $general['confirmScript'] . "?" . $confirmQuery;
|
|
try {
|
|
SendEmail($email, $mailConfirmation, $confirmLink);
|
|
} catch (Exception $e) {
|
|
GracefulExit($errorURL, "{$err}: {$e->getMessage()}");
|
|
}
|
|
|
|
// success
|
|
GracefulExit($successURL, "Anmeldung erfolgreich: Email mit Bestätigungslink wurde an {$email} versandt.");
|
|
?>
|