false, 'message' => 'Invalid request.']); exit; } $email = trim($_POST['email']); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { http_response_code(400); echo json_encode(['success' => false, 'message' => 'Invalid email format.']); exit; } // Use MailService to send a notification require_once __DIR__ . '/mail/MailService.php'; $subject = 'New Waitlist Signup for teenconnect'; $htmlBody = "
A new user has joined the waitlist for teenconnect:
Email: " . htmlspecialchars($email) . "
"; $textBody = "A new user has joined the waitlist for teenconnect:\nEmail: " . htmlspecialchars($email); // sendMail sends to MAIL_TO from .env if $to is null $result = MailService::sendMail(null, $subject, $htmlBody, $textBody); if (!empty($result['success'])) { echo json_encode(['success' => true, 'message' => 'Thank you for joining the waitlist! We will notify you upon launch.']); } else { // In a real app, you would log the detailed error ($result['error']) http_response_code(500); echo json_encode(['success' => false, 'message' => 'We could not process your request at this time. Please try again later.']); }