WebOrbiton
v3.0.0.0

FlatlyPage

171 lines · 5.7 KB
  1. <?php
  2. if (!file_exists('config.php')) {
  3. header('Location: newsletter-unavailable.php');
  4. exit;
  5. }
  6. require_once 'config.php';
  7. $email = $_GET['email'] ?? $_POST['email'] ?? '';
  8. $email = filter_var($email, FILTER_VALIDATE_EMAIL);
  9. if ($_SERVER['REQUEST_METHOD'] === 'POST' && $email) {
  10. $pdo = getDB();
  11. try {
  12. $stmt = $pdo->prepare("DELETE FROM newsletter_subscribers WHERE email = ?");
  13. $stmt->execute([$email]);
  14. if ($stmt->rowCount() > 0) {
  15. showUnsubscribeMessage('Unsubscribed', 'Your email has been removed from our mailing list.', 'success');
  16. } else {
  17. showUnsubscribeMessage('Not Found', 'This email address is not on our list.', 'info');
  18. }
  19. } catch (PDOException $e) {
  20. error_log("Unsubscribe error: " . $e->getMessage());
  21. showUnsubscribeMessage('Error', 'An error occurred. Please try again.', 'error');
  22. }
  23. }
  24. ?>
  25. <!DOCTYPE html>
  26. <html lang="en">
  27. <head>
  28. <meta charset="UTF-8">
  29. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  30. <title>Unsubscribe from Newsletter</title>
  31. <link rel="icon" href="nl.ico?v=<?= filemtime(__DIR__ . '/newsletter/nl.ico') ?>" type="image/x-icon">
  32. <style>
  33. * { margin: 0; padding: 0; box-sizing: border-box; }
  34. body {
  35. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  36. background: #f5f5f5;
  37. display: flex;
  38. align-items: center;
  39. justify-content: center;
  40. min-height: 100vh;
  41. padding: 20px;
  42. }
  43. .unsubscribe-box {
  44. background: white;
  45. border-radius: 8px;
  46. box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  47. max-width: 500px;
  48. width: 100%;
  49. padding: 40px;
  50. }
  51. h1 { color: #333; margin-bottom: 20px; text-align: center; }
  52. p { color: #666; line-height: 1.6; margin-bottom: 20px; }
  53. .form-group { margin-bottom: 20px; }
  54. label { display: block; margin-bottom: 8px; color: #333; font-weight: 500; }
  55. input[type="email"] {
  56. width: 100%;
  57. padding: 12px;
  58. border: 1px solid #ddd;
  59. border-radius: 5px;
  60. font-size: 16px;
  61. }
  62. button {
  63. width: 100%;
  64. padding: 12px;
  65. background: #dc3545;
  66. color: white;
  67. border: none;
  68. border-radius: 5px;
  69. font-size: 16px;
  70. cursor: pointer;
  71. transition: background 0.3s;
  72. }
  73. button:hover { background: #c82333; }
  74. .back-link {
  75. display: block;
  76. text-align: center;
  77. margin-top: 20px;
  78. color: #007bff;
  79. text-decoration: none;
  80. }
  81. </style>
  82. </head>
  83. <body>
  84. <div class="unsubscribe-box">
  85. <h1>Unsubscribe from Newsletter</h1>
  86. <p>We're sorry to see you go. Enter your email address to unsubscribe from our mailing list.</p>
  87. <form method="POST">
  88. <div class="form-group">
  89. <label for="email">Email address:</label>
  90. <input
  91. type="email"
  92. id="email"
  93. name="email"
  94. value="<?= htmlspecialchars($email) ?>"
  95. required
  96. placeholder="your@email.com"
  97. >
  98. </div>
  99. <button type="submit">Unsubscribe</button>
  100. </form>
  101. <a href="<?= SITE_URL ?>" class="back-link">&larr; Back to homepage</a>
  102. </div>
  103. </body>
  104. </html>
  105. <?php
  106. function showUnsubscribeMessage($title, $message, $type) {
  107. $colors = [
  108. 'success' => ['bg' => '#d4edda', 'text' => '#155724'],
  109. 'error' => ['bg' => '#f8d7da', 'text' => '#721c24'],
  110. 'info' => ['bg' => '#d1ecf1', 'text' => '#0c5460']
  111. ];
  112. $color = $colors[$type] ?? $colors['info'];
  113. ?>
  114. <!DOCTYPE html>
  115. <html lang="en">
  116. <head>
  117. <meta charset="UTF-8">
  118. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  119. <title><?= htmlspecialchars($title) ?></title>
  120. <link rel="icon" href="nl.ico?v=<?= filemtime(__DIR__ . '/newsletter/nl.ico') ?>" type="image/x-icon">
  121. <style>
  122. * { margin: 0; padding: 0; box-sizing: border-box; }
  123. body {
  124. font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  125. background: #f5f5f5;
  126. display: flex;
  127. align-items: center;
  128. justify-content: center;
  129. min-height: 100vh;
  130. padding: 20px;
  131. }
  132. .message-box {
  133. background: <?= $color['bg'] ?>;
  134. color: <?= $color['text'] ?>;
  135. border-radius: 8px;
  136. padding: 40px;
  137. max-width: 500px;
  138. text-align: center;
  139. }
  140. h1 { margin-bottom: 15px; }
  141. .btn {
  142. display: inline-block;
  143. margin-top: 20px;
  144. padding: 12px 30px;
  145. background: white;
  146. color: #333;
  147. text-decoration: none;
  148. border-radius: 5px;
  149. }
  150. </style>
  151. </head>
  152. <body>
  153. <div class="message-box">
  154. <h1><?= htmlspecialchars($title) ?></h1>
  155. <p><?= htmlspecialchars($message) ?></p>
  156. <a href="<?= SITE_URL ?>" class="btn">Back to homepage</a>
  157. </div>
  158. </body>
  159. </html>
  160. <?php
  161. exit;
  162. }
  163. ?>