… $buf = preg_replace('~]*>~i', '', $buf); $buf = preg_replace('~]*>~i', '', $buf); // 1) retirer … et ouverts/fermés $buf = preg_replace('~]*>.*?~is', '', $buf); $buf = preg_replace('~]*>~i', '', $buf); // 2) retirer les CSS “globaux” pour éviter d’écraser la home $buf = preg_replace('~]+href="[^"]*(bootstrap[^"]*\.css|mobil_style\.css|site_style\.css|fonts\.googleapis)[^"]*"[^>]*>~i', '', $buf); // 3) retirer le ~i', '', $buf); echo $buf; // garde
+ tes scripts inline utiles } /* ---------- Utils ---------- */ function envget(string $k): string { return trim((string) ($_ENV[$k] ?? $_SERVER[$k] ?? getenv($k) ?? '')); } function t(array $translations, string $key, string $fallback = ''): string { $val = $translations[$key] ?? ''; if ($val === '') { return $fallback; } return (string) $val; } $LOG_DIR = __DIR__ . '/tmp'; $LOG_FILE = $LOG_DIR . '/contact.log'; if (! is_dir($LOG_DIR)) {@mkdir($LOG_DIR, 0770, true);} // dossier local, pas servi publiquement /* ---------- CSRF ---------- */ if (empty($_SESSION['pub_csrf'])) { $_SESSION['pub_csrf'] = bin2hex(random_bytes(32)); } $CSRF = $_SESSION['pub_csrf']; // --- reCAPTCHA v2 (lecture robuste) --- $rcCfg = []; $cfgPath = __DIR__ . '/includes/recaptcha.php'; if (is_file($cfgPath)) { $rcCfg = require $cfgPath; // ['site' => '...', 'secret' => '...'] } $RECAPTCHA_SITE_KEY = trim((string) ($rcCfg['site'] ?? envget('RECAPTCHA_SITE_KEY') ?? '')); $RECAPTCHA_SECRET_KEY = trim((string) ($rcCfg['secret'] ?? envget('RECAPTCHA_SECRET_KEY') ?? '')); // Considère la clé "valide" si longueur réaliste (>= 20) – évite les faux négatifs $HAS_SITE = (strlen($RECAPTCHA_SITE_KEY) >= 20); $HAS_SECRET = (strlen($RECAPTCHA_SECRET_KEY) >= 20); // (optionnel) forcer l’affichage en test: /contact.php?testcaptcha=1 if (($_GET['testcaptcha'] ?? '') === '1') { $HAS_SITE = true; } /* ---------- État page ---------- */ $errors = []; $sent = false; /* ---------- POST ---------- */ if (($_SERVER['REQUEST_METHOD'] ?? '') === 'POST') { // CSRF if (! hash_equals($_SESSION['pub_csrf'] ?? '', $_POST['csrf'] ?? '')) { $errors[] = t($translations, 'contact_err_security', 'Security error. Refresh and try again.'); } // Honeypot anti-bot (Corrigé avec 'company' pour correspondre à votre HTML) if (! empty($_POST['company'] ?? '')) { $errors[] = t($translations, 'contact_err_spam', 'Spam suspected.'); } // Données utilisateur $name = trim($_POST['name'] ?? ''); $profession = trim($_POST['profession'] ?? ''); $city = trim($_POST['city'] ?? ''); $country = trim($_POST['country'] ?? ''); $phone = trim($_POST['phone'] ?? ''); $email = trim($_POST['email'] ?? ''); $site = trim($_POST['site'] ?? ''); $reason = trim($_POST['reason'] ?? ''); // Validations if (mb_strlen($name) < 2) { $errors[] = t($translations, 'contact_err_name', 'Please enter your name.'); } if (mb_strlen($profession) < 2) { $errors[] = t($translations, 'contact_err_profession', 'Please enter your profession.'); } if (mb_strlen($city) < 2) { $errors[] = t($translations, 'contact_err_city', 'Please enter your city.'); } if (mb_strlen($country) < 2) { $errors[] = t($translations, 'contact_err_country', 'Please enter your country.'); } if ($phone === '' && $email === '' && $site === '') { $errors[] = t($translations, 'contact_err_contact', 'Please provide at least one contact (phone, e-mail or website).'); } if ($email !== '' && ! filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors[] = t($translations, 'contact_err_email', 'Please enter a valid email.'); } if (mb_strlen($reason) < 10) { $errors[] = t($translations, 'contact_err_reason', 'Reason is too short.'); } // Envoi if (! $errors) { $to = 'contact@uslugi.fr'; $subjectPrefix = t($translations, 'contact_send_subject_prefix', 'Contact form message — '); $subject = $subjectPrefix . $site; $mailH3 = t($translations, 'contact_mail_h3', 'New message from uslugi.fr'); $lblName = t($translations, 'contact_mail_label_name', 'Name'); $lblProfession = t($translations, 'contact_mail_label_profession', 'Profession'); $lblCity = t($translations, 'contact_mail_label_city', 'City'); $lblCountry = t($translations, 'contact_mail_label_country', 'Country'); $lblPhone = t($translations, 'contact_mail_label_phone', 'Phone'); $lblEmail = t($translations, 'contact_mail_label_email', 'Email'); $lblSite = t($translations, 'contact_mail_label_site', 'Site'); $lblReason = t($translations, 'contact_mail_label_reason', 'Reason'); $html = '

' . htmlspecialchars($mailH3, ENT_QUOTES, 'UTF-8') . '

' . htmlspecialchars($lblName, ENT_QUOTES, 'UTF-8') . ': ' . htmlspecialchars($name) . '

' . htmlspecialchars($lblProfession, ENT_QUOTES, 'UTF-8') . ': ' . htmlspecialchars($profession) . '

' . htmlspecialchars($lblCity, ENT_QUOTES, 'UTF-8') . ': ' . htmlspecialchars($city) . '

' . htmlspecialchars($lblCountry, ENT_QUOTES, 'UTF-8') . ': ' . htmlspecialchars($country) . '

' . htmlspecialchars($lblPhone, ENT_QUOTES, 'UTF-8') . ': ' . htmlspecialchars($phone) . '

' . htmlspecialchars($lblEmail, ENT_QUOTES, 'UTF-8') . ': ' . htmlspecialchars($email) . '

' . htmlspecialchars($lblSite, ENT_QUOTES, 'UTF-8') . ': ' . htmlspecialchars($site) . '

' . htmlspecialchars($lblReason, ENT_QUOTES, 'UTF-8') . ':
' . nl2br(htmlspecialchars($reason)) . '

'; $text = $mailH3 . "\n" . $lblName . ": $name\n" . $lblProfession . ": $profession\n" . $lblCity . ": $city\n" . $lblCountry . ": $country\n" . $lblPhone . ": $phone\n" . $lblEmail . ": $email\n" . $lblSite . ": $site\n\n" . $lblReason . ":\n$reason\n"; try { // From et Reply-To (tableaux) comme attendus par ton wrapper $fromEmail = 'no-reply@uslugi.fr'; $fromName = 'USLUGI.FR'; $replyEmail = filter_var($email, FILTER_VALIDATE_EMAIL) ? $email : 'contact@uslugi.fr'; $replyName = trim($name . ' ' . $profession) ?: 'USLUGI.FR'; // Appel wrapper: retourne [bool $ok, ?string $err] [$ok, $err] = uslugi_mail( $to, $subject, $html, $text, [ 'from' => [$fromEmail, $fromName], 'reply_to' => [$replyEmail, $replyName], // 'bcc' => ['tonmail@gmail.com'], ] ); if ($ok !== true) { throw new RuntimeException('Wrapper mail send failed.'); } // OK $sent = true; $_POST = []; @file_put_contents($LOG_FILE, sprintf( "[%s] OK to=%s subj=%s reply=%s ip=%s\n", date('c'), $to, $site, $email, $_SERVER['REMOTE_ADDR'] ?? '-' ), FILE_APPEND); } catch (Throwable $e) { error_log('MAIL ERROR: ' . $e->getMessage()); @file_put_contents($LOG_FILE, sprintf( "[%s] ERR to=%s subj=%s\n", date('c'), $to, $site ), FILE_APPEND); // Message utilisateur générique (jamais d’info sensible à l’écran) $errors[] = t($translations, 'contact_err_send_failed', 'Failed to send message. Please try later.'); } } } // Lang HTML $langHtml = preg_match('~^[a-z]{2}(-[A-Z]{2})?$~', (string) ($lang ?? '')) ? (string) $lang : 'ru'; /* * Formulaire de recommandation — à intégrer dans la page existante. * Conserve les clés form_index_* déjà utilisées pour le titre, l'introduction, * le bouton, les messages et les champs communs. */ $form_index_status = $form_index_status ?? null; $form_index_message = $form_index_message ?? ''; $form_index_errors = $form_index_errors ?? []; $form_index_old = $form_index_old ?? [ 'name' => '', 'profession' => '', 'city' => '', 'country' => '', 'contact' => '', 'reason' => '', ]; function form_index_value(array $old, string $key): string { return htmlspecialchars((string) ($old[$key] ?? ''), ENT_QUOTES, 'UTF-8'); } function form_index_text(array $translations, string $key, string $fallback): string { $value = $translations[$key] ?? ''; return htmlspecialchars($value !== '' ? (string) $value : $fallback, ENT_QUOTES, 'UTF-8'); } ?> <?php echo htmlspecialchars($translations['seo_contact_title'], ENT_QUOTES, 'UTF-8') ?>

$name ?? '', 'profession' => $profession ?? '', 'city' => $city ?? '', 'country' => $country ?? '', 'phone' => $phone ?? '', 'email' => $email ?? '', 'site' => $site ?? '', 'reason' => $reason ?? '', ]; } if ($form_index_status === 'success'): ?>
✓