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; if (!class_exists('PHPMailer\PHPMailer\PHPMailer')) { return sendEmailNative($data); } try { $mail = new PHPMailer\PHPMailer\PHPMailer(true); $mail->isSMTP(); $mail->Host = $config['smtp_host']; $mail->SMTPAuth = true; $mail->Username = $config['smtp_username']; $mail->Password = $config['smtp_password']; $mail->SMTPSecure = $config['smtp_encryption']; $mail->Port = $config['smtp_port']; $mail->CharSet = 'UTF-8'; $mail->setFrom($config['from_email'], $config['from_name']); $mail->addReplyTo( sanitizeHeaderValue($data['email']), sanitizeHeaderValue($data['firstName'] . ' ' . $data['lastName']) ); $mail->addAddress($config['to_email'], $config['to_name']); $subject = getSubjectLabel($data['subject']); $mail->Subject = '[HexaHost.de] ' . $subject; $mail->isHTML(true); $mail->Body = generateEmailHTML($data); $mail->AltBody = generateEmailText($data); $mail->addCustomHeader('X-Mailer', 'HexaHost Contact Form'); $mail->addCustomHeader('X-Priority', '3'); $mail->addCustomHeader('X-MSMail-Priority', 'Normal'); $mail->addCustomHeader('Importance', 'Normal'); $mail->addCustomHeader('X-Report-Abuse', 'Please report abuse here: abuse@hexahost.de'); $mail->send(); return true; } catch (Exception $e) { error_log('HexaHost Contact Form Error: ' . $e->getMessage()); return false; } } function sendEmailNative($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', ]; 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