json_last_error_msg()]); if ($json === false) { // This should not happen, but … $json = '{"jsonError":"unknown"}'; } // Set HTTP response status code to: 500 - Internal Server Error http_response_code(500); } header('Content-type: application/json'); echo $json; } if ($_SERVER["REQUEST_METHOD"] == "POST") { $response = array(); if ( empty($_POST['message']) || empty($_POST['email']) || empty($_POST['name']) || $_POST['captcha'] != 'Nudelsuppe' ) { if (empty($_POST['message'])) { $response['errors'][] = 'Du hast keine Nachricht eingegeben.'; } if (empty($_POST['email'])) { $response['errors'][] = 'Du hast keine E-Mail-Adresse eingegeben.'; } if (empty($_POST['name'])) { $response['errors'][] = 'Du hast keinen Namen eingegeben.'; } if ($_POST['captcha'] != 'Nudelsuppe') { $response['errors'][] = 'Wir glauben du bist ein Bot.'; } } else { $message = sanitize_text('message'); $name = sanitize_text('name'); $email = sanitize_text('email'); if (!send_message_to_office($message, $name, $email)) { $response['errors'][] = 'Deine Nachricht konnte nicht übermittelt werden.'; } else { $response['status'] = 'ok'; } } send_response($response); } else { http_response_code(404); }