<?php
require_once __DIR__ . '/../includes/api-helpers.php';
api_require_post();
if (api_is_spam()) api_json(true, 'Subscribed!');

$email = api_str('email', 160);
if (!api_valid_email($email)) api_json(false, 'Please enter a valid email address.');

$stmt = db()->prepare('INSERT IGNORE INTO newsletter_subscribers (email) VALUES (?)');
$stmt->execute([$email]);

api_json(true, 'Thanks for subscribing!');
