'POST only'])); $data = json_decode(file_get_contents('php://input'), true); $email = filter_var($data['email'] ?? '', FILTER_VALIDATE_EMAIL); $name = substr($data['name'] ?? '', 0, 100); $form_id = substr($data['form_id'] ?? 'default', 0, 50); if (!$email) die(json_encode(['error'=>'Invalid email'])); $db = new PDO('pgsql:host=10.1.0.3;port=5432;dbname=adx_system','admin',weval_secret('WEVAL_PG_ADMIN_PASS')); $db->exec("SET search_path TO admin"); try { $db->exec("CREATE TABLE IF NOT EXISTS form_submissions (id SERIAL PRIMARY KEY, form_id TEXT, email TEXT, name TEXT, ip TEXT, created_at TIMESTAMP DEFAULT NOW())"); $db->prepare("INSERT INTO form_submissions (form_id, email, name, ip) VALUES (?, ?, ?, ?)") ->execute([$form_id, $email, $name, $_SERVER['REMOTE_ADDR'] ?? '']); // Also add to send_contacts if not exists $exists = $db->prepare("SELECT COUNT(*) FROM send_contacts WHERE email = ?"); $exists->execute([$email]); if ($exists->fetchColumn() == 0) { $db->prepare("INSERT INTO send_contacts (email, first_name, status, source, score) VALUES (?, ?, 'active', ?, 'hot')") ->execute([$email, $name, 'form_' . $form_id]); } echo json_encode(['ok'=>1, 'message'=>'Subscribed']); } catch (Exception $e) { echo json_encode(['error'=>'Server error']); }