2026-02-05 04:11:15 +00:00
|
|
|
<?php
|
|
|
|
|
header("Content-Type: application/json");
|
|
|
|
|
header("Access-Control-Allow-Origin: *");
|
|
|
|
|
header("Access-Control-Allow-Methods: POST");
|
|
|
|
|
header("Access-Control-Allow-Headers: Content-Type");
|
|
|
|
|
|
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] === "OPTIONS") {
|
|
|
|
|
http_response_code(200);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
|
|
|
|
|
http_response_code(405);
|
|
|
|
|
echo json_encode(["error" => "Method not allowed"]);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$input = json_decode(file_get_contents("php://input"), true);
|
|
|
|
|
$email = filter_var($input["email"] ?? "", FILTER_VALIDATE_EMAIL);
|
|
|
|
|
$source = htmlspecialchars($input["source"] ?? "unknown");
|
|
|
|
|
$page = htmlspecialchars($input["page"] ?? "unknown");
|
|
|
|
|
|
|
|
|
|
if (!$email) {
|
|
|
|
|
http_response_code(400);
|
|
|
|
|
echo json_encode(["error" => "Invalid email"]);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Log the lead
|
|
|
|
|
$log_entry = date("Y-m-d H:i:s") . " | $email | $source | $page\n";
|
2026-03-21 10:13:14 +00:00
|
|
|
file_put_contents("/var/www/ukaiautomation/api/leads.log", $log_entry, FILE_APPEND | LOCK_EX);
|
2026-02-05 04:11:15 +00:00
|
|
|
|
|
|
|
|
// Send notification email (optional - uncomment if you want email alerts)
|
2026-03-21 09:48:46 +00:00
|
|
|
// mail("peter.foster@ukaiautomation.co.uk", "New Lead: $email", "Source: $source\nPage: $page");
|
2026-02-05 04:11:15 +00:00
|
|
|
|
|
|
|
|
echo json_encode(["success" => true, "message" => "Lead captured"]);
|