false, 'message' => 'Method not allowed']); exit; } function checkRateLimit($ip) { global $config; $cache_file = sys_get_temp_dir() . '/hexahost_contact_' . md5($ip) . '.txt'; $current_time = time(); $data = ['requests' => []]; $handle = @fopen($cache_file, 'c+'); if ($handle === false) { return true; } try { if (!flock($handle, LOCK_EX)) { return true; } $contents = stream_get_contents($handle); if ($contents !== false && $contents !== '') { $decoded = json_decode($contents, true); if (is_array($decoded) && isset($decoded['requests'])) { $data = $decoded; } } $data['requests'] = array_values(array_filter( $data['requests'], static fn($timestamp) => ($current_time - (int) $timestamp) < 3600 )); if (count($data['requests']) >= $config['max_requests_per_hour']) { return false; } $data['requests'][] = $current_time; ftruncate($handle, 0); rewind($handle); fwrite($handle, json_encode($data)); } finally { flock($handle, LOCK_UN); fclose($handle); } return true; } function checkHoneypot($data) { global $config; $honeypot_field = $config['honeypot_field']; return empty($data[$honeypot_field]); } function sanitizeFormField($input) { return strip_tags(trim((string) $input)); } function getSubjectLabel($subjectKey) { $map = getContactSubjectMap(); return $map[$subjectKey] ?? 'Neue Kontaktanfrage'; } function sendEmail($data) { global $config; $subject = '[HexaHost.de] ' . getSubjectLabel($data['subject']); $replyName = sanitizeHeaderValue($data['firstName'] . ' ' . $data['lastName']); $replyEmail = sanitizeHeaderValue($data['email']); $headers = [ 'From: ' . $config['from_name'] . ' <' . $config['from_email'] . '>', 'Reply-To: ' . $replyName . ' <' . $replyEmail . '>', 'MIME-Version: 1.0', 'Content-Type: text/html; charset=UTF-8', 'X-Mailer: HexaHost Contact Form', 'X-Priority: 3', 'X-MSMail-Priority: Normal', 'Importance: Normal', 'X-Report-Abuse: Please report abuse here: abuse@hexahost.de', ]; // Native PHP Mailversand ohne externe Libraries return mail($config['to_email'], $subject, generateEmailHTML($data), implode("\r\n", $headers)); } function generateEmailHTML($data) { $subject_text = htmlspecialchars(getSubjectLabel($data['subject']), ENT_QUOTES, 'UTF-8'); $html = '
HexaHost.de Kontaktformular