From 731631ecd5ba570349b14ec0fb57b22c47f9cb2e Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Fri, 17 Jul 2026 19:09:39 -0500 Subject: [PATCH] feat(site): email launch-list capture with a PHP/MySQL endpoint A signup form in the closing section posts to subscribe.php (ships in the build): PDO/MySQL, honeypot, idempotent insert, optional mail() notify. DB creds live in a gitignored config kept above the web root; schema and setup in server/. Signed-off-by: Diego Resendez --- .gitignore | 4 + public/subscribe.php | 84 +++++++++++++++ server/README.md | 24 +++++ server/schema.sql | 7 ++ server/subscribe.config.example.php | 18 ++++ src/components/sections/HonestBeta.astro | 127 +++++++++++++++++++++++ 6 files changed, 264 insertions(+) create mode 100644 public/subscribe.php create mode 100644 server/README.md create mode 100644 server/schema.sql create mode 100644 server/subscribe.config.example.php diff --git a/.gitignore b/.gitignore index dc6cd95..b437387 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,10 @@ node_modules/ .env .env.production +# real DB credentials for the launch-list endpoint (never commit) +subscribe.config.php +**/subscribe.config.php + # macOS .DS_Store diff --git a/public/subscribe.php b/public/subscribe.php new file mode 100644 index 0000000..080dbe9 --- /dev/null +++ b/public/subscribe.php @@ -0,0 +1,84 @@ + $ok, 'message' => $message]); + } else { + header('Location: /?subscribed=' . ($ok ? '1' : '0') . '#subscribe'); + } + exit; +} + +$wantsJson = isset($_SERVER['HTTP_X_REQUESTED_WITH']) + && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'fetch'; + +if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST') { + respond(false, 405, 'Method not allowed.', $wantsJson); +} + +// Honeypot: bots fill hidden fields, people don't. Accept silently, store nothing. +if (trim((string) ($_POST['website'] ?? '')) !== '') { + respond(true, 200, "You're on the list.", $wantsJson); +} + +$email = trim((string) ($_POST['email'] ?? '')); +if ($email === '' || strlen($email) > 254 || !filter_var($email, FILTER_VALIDATE_EMAIL)) { + respond(false, 422, 'Please enter a valid email address.', $wantsJson); +} + +// Config one level above the web root is preferred; same-dir is a fallback. +$configFile = __DIR__ . '/../subscribe.config.php'; +if (!is_file($configFile)) { + $configFile = __DIR__ . '/subscribe.config.php'; +} +if (!is_file($configFile)) { + error_log('subscribe: missing subscribe.config.php'); + respond(false, 500, 'Signups are not configured yet.', $wantsJson); +} +$config = require $configFile; + +try { + $pdo = new PDO($config['dsn'], $config['user'], $config['pass'], [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_EMULATE_PREPARES => false, + ]); + // Unique index on email makes this idempotent — a repeat signup is a no-op. + $stmt = $pdo->prepare( + 'INSERT INTO subscribers (email, created_at, ip) VALUES (:email, NOW(), :ip) + ON DUPLICATE KEY UPDATE email = email' + ); + $stmt->execute([ + ':email' => $email, + ':ip' => $_SERVER['REMOTE_ADDR'] ?? null, + ]); +} catch (Throwable $e) { + error_log('subscribe: ' . $e->getMessage()); + respond(false, 500, 'Could not save that right now — try again later.', $wantsJson); +} + +// Optional heads-up email. Never fatal: the DB row is the source of truth. +if (!empty($config['notify'])) { + @mail( + (string) $config['notify'], + 'Green Tea: new subscriber', + "New launch-list signup: {$email}", + 'From: Green Tea <' . $config['notify'] . '>' + ); +} + +respond(true, 200, "You're on the list — we'll ping you at 1.0.", $wantsJson); diff --git a/server/README.md b/server/README.md new file mode 100644 index 0000000..a378283 --- /dev/null +++ b/server/README.md @@ -0,0 +1,24 @@ +# Launch-list backend (cPanel) + +The email capture on the site posts to `subscribe.php`, which ships in the build +(`public/subscribe.php` → `dist/subscribe.php`). To wire it up on cPanel: + +1. **Create the DB** in cPanel → MySQL Databases. Note db name, user, password. +2. **Create the table**: run `schema.sql` in phpMyAdmin against that DB. +3. **Add credentials**: copy `subscribe.config.example.php` to `subscribe.config.php`, + fill in the DB values, and upload it **one level above** the subdomain's docroot + (so it is never web-servable). `subscribe.php` looks there first. +4. **Deploy** the built `dist/` into the subdomain docroot. `subscribe.php` is already inside it. +5. **Smoke test**: + ``` + curl -i -X POST -H 'X-Requested-With: fetch' \ + --data 'email=test@example.com' \ + https://green-tea.expressive-tea.io/subscribe.php + ``` + Expect `{"ok":true,...}` and a row in `subscribers`. + +Notes: +- Duplicate signups are a silent success (unique index on `email`). +- A hidden honeypot field blocks basic bots. +- No-JS visitors are redirected to `/?subscribed=1`; with JS they get inline feedback. +- No rate limiting yet — add one at the cPanel/CDN layer if signups get abused. diff --git a/server/schema.sql b/server/schema.sql new file mode 100644 index 0000000..18f301a --- /dev/null +++ b/server/schema.sql @@ -0,0 +1,7 @@ +-- Launch-list table for subscribe.php. Run once against the green-tea DB. +CREATE TABLE IF NOT EXISTS subscribers ( + id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, + email VARCHAR(254) NOT NULL UNIQUE, + created_at DATETIME NOT NULL, + ip VARCHAR(45) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/server/subscribe.config.example.php b/server/subscribe.config.example.php new file mode 100644 index 0000000..52e432b --- /dev/null +++ b/server/subscribe.config.example.php @@ -0,0 +1,18 @@ + 'mysql:host=localhost;dbname=YOUR_DB;charset=utf8mb4', + 'user' => 'YOUR_DB_USER', + 'pass' => 'YOUR_DB_PASSWORD', + 'notify' => 'support@expressive-tea.io', // set to '' to skip notification emails +]; diff --git a/src/components/sections/HonestBeta.astro b/src/components/sections/HonestBeta.astro index f36df89..8b886fe 100644 --- a/src/components/sections/HonestBeta.astro +++ b/src/components/sections/HonestBeta.astro @@ -10,6 +10,27 @@ ergonomics. If you're tired of maintaining someone else's foundation, come try it.

+ +
Read the docs @@ -49,4 +70,110 @@ font-size: 1.5rem; color: var(--matcha); } + + .subscribe { + max-width: 30rem; + margin: 0 auto 2.5rem; + } + + .subscribe__lead { + margin: 0 0 0.9rem; + color: var(--dim); + font-size: 0.95rem; + } + + .subscribe__row { + display: flex; + gap: 0.6rem; + } + + .subscribe__input { + flex: 1; + min-width: 0; + padding: 0.7rem 0.9rem; + border-radius: 8px; + border: 1px solid color-mix(in srgb, var(--dim) 35%, transparent); + background: var(--base); + color: var(--ink); + font-size: 0.95rem; + } + + .subscribe__input:focus-visible { + outline: 2px solid var(--matcha); + outline-offset: 1px; + } + + /* honeypot — kept in the layout for bots, off-screen for humans */ + .subscribe__hp { + position: absolute; + left: -9999px; + width: 1px; + height: 1px; + opacity: 0; + } + + .subscribe__msg { + margin: 0.75rem 0 0; + min-height: 1.2em; + font-size: 0.9rem; + color: var(--matcha); + } + + .subscribe__msg[data-error] { + color: var(--violet); + } + + .sr-only { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + margin: -1px; + overflow: hidden; + clip: rect(0, 0, 0, 0); + white-space: nowrap; + border: 0; + } + + @media (max-width: 480px) { + .subscribe__row { + flex-direction: column; + } + } + +