��<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Unsubscribe</title> <style> body { margin: 0; font-family: Arial, sans-serif; background-color: #f8f9fa; color: #333; } .unsubscribe-section { background-color: #f4f4f4; padding: 30px; border-radius: 12px; box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1); max-width: 600px; margin: 40px auto 0; /* Positioned at the top and slightly down */ text-align: center; } .unsubscribe-section h2 { font-size: 24px; margin-bottom: 20px; color: #444; } .unsubscribe-section form { display: flex; gap: 10px; justify-content: center; } .unsubscribe-section input[type="email"] { flex: 1; padding: 12px; border: 1px solid #ccc; border-radius: 6px; font-size: 16px; } .unsubscribe-section button { padding: 12px 20px; background-color: #007bff; color: #fff; border: none; border-radius: 6px; font-size: 16px; cursor: pointer; transition: background-color 0.3s ease; } .unsubscribe-section button:hover { background-color: #0056b3; } .success-message { margin-top: 15px; display: none; font-size: 16px; color: #28a745; font-weight: bold; } .error-message { margin-top: 15px; display: none; font-size: 16px; color: #dc3545; font-weight: bold; } </style> </head> <body> <div class="unsubscribe-section"> <h2>Unsubscribe from Our Mailing List</h2> <form id="unsubscribe-form" onsubmit="handleUnsubscribe(event)"> <input type="email" id="email" placeholder="Enter your email" required /> <button type="submit">Unsubscribe</button> </form> <div class="success-message" id="success-message"> You have successfully unsubscribed. </div> <div class="error-message" id="error-message"> There was an error. Please try again later. </div> </div> <script> async function handleUnsubscribe(event) { event.preventDefault(); // Prevent default form submission behavior const emailInput = document.getElementById('email'); const successMessage = document.getElementById('success-message'); const errorMessage = document.getElementById('error-message'); const form = document.getElementById('unsubscribe-form'); const email = emailInput.value; // Display success message immediately successMessage.style.display = 'block'; form.style.display = 'none'; try { // Replace YOUR_WEB_APP_URL_HERE with the actual Web App URL const response = await fetch('https://script.google.com/macros/s/AKfycbzoPqiZgcEg0sJvHQfUTf0D8sPK_DJhm0BAEI2hK29GT3fHftlbUUCX_FVW5fJ0LbAn/exec', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: `email=${encodeURIComponent(email)}`, }); if (!response.ok) { // If backend fails, hide success message and show error successMessage.style.display = 'none'; form.style.display = 'block'; errorMessage.style.display = 'block'; } } catch (error) { // Show error message if the request fails successMessage.style.display = 'none'; form.style.display = 'block'; errorMessage.style.display = 'block'; } } </script> </body> </html>