-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunsubscribe.php
More file actions
39 lines (38 loc) · 1.5 KB
/
unsubscribe.php
File metadata and controls
39 lines (38 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
require_once __DIR__ . '/config.php';
$token = trim($_GET['token'] ?? '');
$msg = ''; $error = '';
if (!$token) { $error = 'Invalid unsubscribe link.'; }
else {
$sub = dbRow('SELECT * FROM email_subscriptions WHERE unsubscribe_token=? LIMIT 1', 's', $token);
if (!$sub) {
$error = 'This unsubscribe link is invalid.';
} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
dbq('DELETE FROM email_subscriptions WHERE unsubscribe_token=?', 's', $token);
$msg = 'You have been unsubscribed successfully.';
}
}
$pageTitle = 'Unsubscribe — ' . SITE_NAME;
include __DIR__ . '/includes/header.php';
?>
<div class="row justify-content-center mt-5">
<div class="col-md-5 text-center">
<?php if ($msg): ?>
<i class="bi bi-envelope-x text-muted" style="font-size:4rem;"></i>
<h3 class="mt-3">Unsubscribed</h3>
<p><?= e($msg) ?></p>
<?php elseif ($error): ?>
<p class="text-danger"><?= e($error) ?></p>
<?php elseif ($sub): ?>
<i class="bi bi-envelope-dash text-warning" style="font-size:4rem;"></i>
<h3 class="mt-3">Unsubscribe?</h3>
<p>You are currently subscribed with: <strong><?= e($sub['email']) ?></strong></p>
<form method="POST">
<?= csrfField() ?>
<button type="submit" class="btn btn-danger"><i class="bi bi-x-circle me-1"></i>Yes, Unsubscribe Me</button>
<a href="<?= SITE_URL ?>" class="btn btn-outline-secondary ms-2">Cancel</a>
</form>
<?php endif; ?>
</div>
</div>
<?php include __DIR__ . '/includes/footer.php'; ?>