NewsPen/unsubscribe.php

45 lines
1.3 KiB
PHP
Raw Normal View History

2018-05-21 18:06:04 -06:00
<?php
2018-05-21 18:23:03 -06:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
2018-05-21 18:06:04 -06:00
require __DIR__ . "/required.php";
require __DIR__ . "/lib/iputils.php";
2018-05-22 00:50:22 -06:00
?>
<!DOCTYPE html>
<title>Unsubscribe</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<?php
2018-05-21 18:06:04 -06:00
2018-05-22 00:50:22 -06:00
if (isset($VARS['a'])) {
echo "<p>";
$address = $VARS['a'];
2018-05-21 18:06:04 -06:00
2018-05-22 00:50:22 -06:00
engageRateLimit();
2018-05-21 18:06:04 -06:00
2018-05-22 00:50:22 -06:00
if (!filter_var($address, FILTER_VALIDATE_EMAIL)) {
die("Invalid email address.");
}
2018-05-21 18:06:04 -06:00
2018-05-22 00:50:22 -06:00
$address = str_replace("%", '\%', $address);
2018-05-21 18:06:04 -06:00
2018-05-22 00:50:22 -06:00
if ($database->has('addresses', ['email' => $address])) {
$count = $database->count('addresses', ['email' => $address]);
$database->delete('addresses', ['email' => $address]);
die("$address has been removed from $count mailing " . ($count === 1 ? "list" : "lists") . ".");
} else {
die("$address has already been removed.");
}
2018-05-21 18:06:04 -06:00
} else {
2018-05-22 00:50:22 -06:00
?>
<p>Enter your email address below to unsubscribe:</p>
<form action="" method="GET">
<input type="email" name="a" placeholder="xxxxx@example.com" required />
<br />
<input type="submit" value="Unsubscribe" />
</form>
<?php
2018-05-21 18:06:04 -06:00
}