\r\n" . "Reply-To: $email\r\n" . "X-Mailer: PHP/" . phpversion() ); if ($mailSent) { $success = true; } else { $errorMessage = 'Es gab ein Problem beim Senden Ihrer Nachricht. Bitte versuchen Sie es später erneut.'; error_log("Mail sending failed"); } } // Handle the response if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') { // Ajax request - return JSON header('Content-Type: application/json'); echo json_encode([ 'success' => $success, 'message' => $errorMessage ]); } else { // Regular form submission - redirect with status if ($success) { header('Location: index.html?form_success=1#contact'); } else { header('Location: index.html?form_error=' . urlencode($errorMessage) . '#contact'); } } ?>