36 lines
1.3 KiB
PHP
36 lines
1.3 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
|
|
// Basic input validation
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST' || empty($_POST['email'])) {
|
|
http_response_code(400);
|
|
echo json_encode(['success' => 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 = "<p>A new user has joined the waitlist for teenconnect:</p><p><b>Email:</b> " . htmlspecialchars($email) . "</p>";
|
|
$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.']);
|
|
}
|