$message]; if (!empty($_GET["debug"]) && $details) { $response["details"] = $details; } echo json_encode($response); exit; } if ($_SERVER["REQUEST_METHOD"] === "POST") { $data = json_decode(file_get_contents("php://input"), true); $name = strip_tags($data["name"] ?? ""); $email = filter_var($data["email"] ?? "", FILTER_SANITIZE_EMAIL); $phone = strip_tags($data["phone"] ?? ""); $service = strip_tags($data["service"] ?? ""); $message = strip_tags($data["message"] ?? ""); $language = $data["language"] ?? "hu"; $recaptchaToken = $data["recaptchaToken"] ?? ""; $recaptchaAction = $data["recaptchaAction"] ?? ""; if (!$recaptchaToken) { json_error("Missing reCaptcha token"); } // 1. Verify reCaptcha v3 $verifyResponse = null; if (function_exists("curl_init")) { $ch = curl_init("https://www.google.com/recaptcha/api/siteverify"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([ "secret" => $secretKey, "response" => $recaptchaToken, ])); $verifyResponse = curl_exec($ch); curl_close($ch); } else { $verifyResponse = file_get_contents( "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$recaptchaToken" ); } if ($verifyResponse === false || !$verifyResponse) { $last = error_get_last(); json_error("reCaptcha verification failed", 400, $last ? $last["message"] : "No response"); } $responseData = json_decode($verifyResponse); if (!$responseData) { json_error("reCaptcha verification failed", 400, "Invalid JSON response"); } if ( !$responseData->success || $responseData->action !== $expectedAction || $responseData->score < $minScore ) { json_error("reCaptcha verification failed", 400, json_encode($responseData)); } $isEnglish = $language === "en"; $subject = $isEnglish ? "Website message: $name ($service)" : "Weboldal uzenet: $name ($service)"; $title = $isEnglish ? "New message" : "Uj uzenet"; $labelName = $isEnglish ? "Name" : "Nev"; $labelEmail = $isEnglish ? "Email" : "Email"; $labelPhone = $isEnglish ? "Phone" : "Telefonszam"; $labelService = $isEnglish ? "Service type" : "Szolgaltatas tipusa"; $labelMessage = $isEnglish ? "Message" : "Uzenet"; $htmlEmail = "
"; $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $headers .= "From: