false, 'error' => 'Method not allowed']); exit; } require_once __DIR__ . '/vendor/autoload.php'; use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception as MailException; // ── Input ────────────────────────────────────────────────────────────── $raw = file_get_contents('php://input') ?: '{}'; $input = json_decode($raw, true) ?: []; $email = trim((string)($input['email'] ?? $_POST['email'] ?? '')); $source = trim((string)($input['source'] ?? $_POST['source'] ?? 'waitlist')); $name = trim((string)($input['name'] ?? $_POST['name'] ?? '')); // ── Validate ─────────────────────────────────────────────────────────── if (!$email) { http_response_code(400); echo json_encode(['ok' => false, 'error' => 'Email address is required']); exit; } if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { http_response_code(422); echo json_encode(['ok' => false, 'error' => 'Please enter a valid email address']); exit; } // Basic honeypot / rate limit: reject obviously bad inputs if (strlen($email) > 254 || preg_match('/[<>"\']/', $email)) { http_response_code(422); echo json_encode(['ok' => false, 'error' => 'Invalid email address']); exit; } // ── SMTP config from environment ─────────────────────────────────────── $smtpHost = $_SERVER['SMTP_HOST'] ?? $_ENV['SMTP_HOST'] ?? getenv('SMTP_HOST') ?: ''; $smtpPort = (int)($_SERVER['SMTP_PORT'] ?? $_ENV['SMTP_PORT'] ?? getenv('SMTP_PORT') ?: 587); $smtpUser = $_SERVER['SMTP_USER'] ?? $_ENV['SMTP_USER'] ?? getenv('SMTP_USER') ?: ''; $smtpPass = $_SERVER['SMTP_PASS'] ?? $_ENV['SMTP_PASS'] ?? getenv('SMTP_PASS') ?: ''; $smtpFrom = $_SERVER['SMTP_FROM'] ?? $_ENV['SMTP_FROM'] ?? getenv('SMTP_FROM') ?: $smtpUser; $smtpFromName = $_SERVER['SMTP_FROM_NAME'] ?? $_ENV['SMTP_FROM_NAME'] ?? getenv('SMTP_FROM_NAME') ?: 'Tas Planning Assistant'; $notifyEmail = $_SERVER['NOTIFY_EMAIL'] ?? $_ENV['NOTIFY_EMAIL'] ?? getenv('NOTIFY_EMAIL') ?: $smtpUser; $errors = []; // ── 1. Send confirmation email to subscriber ─────────────────────────── if ($smtpHost && $smtpUser) { try { $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = $smtpHost; $mail->SMTPAuth = true; $mail->Username = $smtpUser; $mail->Password = $smtpPass; $mail->SMTPSecure = $smtpPort === 465 ? PHPMailer::ENCRYPTION_SMTPS : PHPMailer::ENCRYPTION_STARTTLS; $mail->Port = $smtpPort; $mail->CharSet = 'UTF-8'; $mail->setFrom($smtpFrom, $smtpFromName); $mail->addAddress($email, $name ?: ''); $mail->addReplyTo($smtpFrom, $smtpFromName); $mail->isHTML(true); $mail->Subject = "You're on the waitlist — Tasmania's AI Planning Scheme Pro"; $mail->Body = confirmationHtml($email, $name); $mail->AltBody = confirmationText($email, $name); $mail->send(); } catch (MailException $e) { // Log but don't fail the whole request — notification is non-critical $errors[] = 'confirmation_mail: ' . $mail->ErrorInfo; error_log('[waitlist] Confirmation mail failed: ' . $mail->ErrorInfo); } // ── 2. Send admin notification ───────────────────────────────────── if ($notifyEmail) { try { $notify = new PHPMailer(true); $notify->isSMTP(); $notify->Host = $smtpHost; $notify->SMTPAuth = true; $notify->Username = $smtpUser; $notify->Password = $smtpPass; $notify->SMTPSecure = $smtpPort === 465 ? PHPMailer::ENCRYPTION_SMTPS : PHPMailer::ENCRYPTION_STARTTLS; $notify->Port = $smtpPort; $notify->CharSet = 'UTF-8'; $notify->setFrom($smtpFrom, $smtpFromName); $notify->addAddress($notifyEmail); $notify->Subject = "New waitlist signup: {$email}"; $notify->Body = "

Email: {$email}

" . "

Source: {$source}

" . "

Time: " . date('d M Y H:i:s T') . "

"; $notify->AltBody = "New waitlist signup\nEmail: {$email}\nSource: {$source}\nTime: " . date('d M Y H:i:s T'); $notify->isHTML(true); $notify->send(); } catch (MailException $e) { $errors[] = 'notify_mail: ' . $notify->ErrorInfo; error_log('[waitlist] Notify mail failed: ' . $notify->ErrorInfo); } } } else { // No SMTP configured — log a warning but still return success error_log('[waitlist] SMTP not configured. Set SMTP_HOST and SMTP_USER in environment.'); $errors[] = 'smtp_not_configured'; } // ── 3. Log to telemetry DB via the API (best-effort) ─────────────────── $apiBase = $_SERVER['APP_API_BASE'] ?? $_ENV['APP_API_BASE'] ?? getenv('APP_API_BASE') ?: 'https://api.modulos.com.au/ask'; $telUrl = preg_replace('/\/ask\/?$/', '', $apiBase) . '/telemetry'; $telPayload = json_encode([ 'type' => 'waitlist_join', 'email' => $email, 'source'=> $source, 'ts' => date('c'), ]); // Fire-and-forget with a short timeout $ctx = stream_context_create(['http' => [ 'method' => 'POST', 'header' => "Content-Type: application/json\r\n", 'content' => $telPayload, 'timeout' => 2, 'ignore_errors' => true, ]]); @file_get_contents($telUrl, false, $ctx); // ── Response ─────────────────────────────────────────────────────────── echo json_encode([ 'ok' => true, 'message' => "You're on the list! We'll be in touch when Pro launches.", 'warnings'=> $errors ?: null, ]); // ── Email templates ──────────────────────────────────────────────────── function confirmationHtml(string $email, string $name = ''): string { $greeting = $name ? "Hi {$name}," : 'Hi there,'; return <<
Tasmanian Planning Scheme

You're on the Pro waitlist

{$greeting}

Thanks for joining the waitlist for Tasmanian Planning Scheme Pro. We'll email you as soon as it's available — including early-access pricing for waitlist members.

What's included in Pro

✓  Full planning report from one brief
✓  Zone + codes tables with A/P assessment
✓  Clause-linked sources throughout
✓  Google Docs export
✓  NCC/AS hooks when released

In the meantime, the free assistant is available at tasplanning.report — ask questions about zones, overlays, setbacks, and acceptable solutions with full clause citations.

Try the free assistant →

You're receiving this because you signed up at tasplanning.report.
To unsubscribe, reply to this email with "unsubscribe" in the subject.

HTML; } function confirmationText(string $email, string $name = ''): string { $greeting = $name ? "Hi {$name}," : 'Hi there,'; return <<