… $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 if (! empty($_POST['website'] ?? '')) { $errors[] = t($translations, 'contact_err_spam', 'Spam suspected.'); } // Données utilisateur $prenom = trim($_POST['prenom'] ?? ''); $nom = trim($_POST['nom'] ?? ''); $email = trim($_POST['email'] ?? ''); $sujet = trim($_POST['sujet'] ?? ''); $message = trim($_POST['message'] ?? ''); // Validations if (mb_strlen($prenom) < 2) { $errors[] = t($translations, 'contact_err_prenom', 'Please enter your first name.'); } if (mb_strlen($nom) < 2) { $errors[] = t($translations, 'contact_err_nom', 'Please enter your last name.'); } if (! filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors[] = t($translations, 'contact_err_email', 'Please enter a valid email.'); } if (mb_strlen($sujet) < 3) { $errors[] = t($translations, 'contact_err_sujet', 'Subject is too short.'); } if (mb_strlen($message) < 10) { $errors[] = t($translations, 'contact_err_message', 'Message is too short.'); } // reCAPTCHA serveur if ($HAS_SECRET) { $token = $_POST['g-recaptcha-response'] ?? ''; if ($token === '') { $errors[] = t($translations, 'contact_err_captcha_required', 'Please confirm you are not a robot.'); } else { $resp = @file_get_contents( 'https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($RECAPTCHA_SECRET_KEY) . '&response=' . urlencode($token) . '&remoteip=' . urlencode($_SERVER['REMOTE_ADDR'] ?? '') ); $ver = $resp ? json_decode($resp, true) : ['success' => false]; if (empty($ver['success'])) { $errors[] = t($translations, 'contact_err_captcha_failed', 'reCAPTCHA verification failed.'); } } } // Envoi if (! $errors) { $to = 'contact@uslugi.fr'; $subjectPrefix = t($translations, 'contact_send_subject_prefix', 'Contact form message — '); $subject = $subjectPrefix . $sujet; $mailH3 = t($translations, 'contact_mail_h3', 'New message from uslugi.fr'); $lblName = t($translations, 'contact_mail_label_name', 'Name'); $lblEmail = t($translations, 'contact_mail_label_email', 'Email'); $lblSubject = t($translations, 'contact_mail_label_subject', 'Subject'); $lblMessage = t($translations, 'contact_mail_label_message', 'Message'); $html = '

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

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

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

' . htmlspecialchars($lblSubject, ENT_QUOTES, 'UTF-8') . ': ' . htmlspecialchars($sujet) . '

' . htmlspecialchars($lblMessage, ENT_QUOTES, 'UTF-8') . ':
' . nl2br(htmlspecialchars($message)) . '

'; $text = $mailH3 . "\n" . $lblName . ": $prenom $nom\n" . $lblEmail . ": $email\n" . $lblSubject . ": $sujet\n\n" . $lblMessage . ":\n$message\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($prenom . ' ' . $nom) ?: '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, $sujet, $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, $sujet ), 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'; ?> <?php echo htmlspecialchars($translations['seo_contact_title'], ENT_QUOTES, 'UTF-8') ?>