| Current Path : /home/happyrenas/find.myreco.online/ |
Linux webd005.cluster105.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 |
| Current File : /home/happyrenas/find.myreco.online/traitement_contact.php |
<?php
include("includes/mail_find.php");
include("configuration.php");
/*
|--------------------------------------------------------------------------
| Vérification Turnstile
|--------------------------------------------------------------------------
*/
function verifierTurnstile(?string $token): array
{
if (empty($token)) {
return [
'success' => false,
'error-codes' => ['token-vide']
];
}
$postFields = http_build_query([
'secret' => TURNSTILE_SECRET_KEY,
'response' => $token,
'remoteip' => $_SERVER['REMOTE_ADDR'] ?? ''
]);
$ch = curl_init('https://challenges.cloudflare.com/turnstile/v0/siteverify');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);
if ($response === false) {
$erreurCurl = curl_error($ch);
curl_close($ch);
return [
'success' => false,
'error-codes' => ['curl-error'],
'curl-error' => $erreurCurl
];
}
curl_close($ch);
$resultat = json_decode($response, true);
if (!is_array($resultat)) {
return [
'success' => false,
'error-codes' => ['json-invalide']
];
}
return $resultat;
}
/*
|--------------------------------------------------------------------------
| Vérification méthode
|--------------------------------------------------------------------------
*/
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
afficherPageRetour(
'Accès non autorisé',
'Cette page ne peut être appelée que depuis le formulaire.',
'error',
'contact.php'
);
}
/*
|--------------------------------------------------------------------------
| Récupération
|--------------------------------------------------------------------------
*/
$nom = nettoyerChamp($_POST['nom'] ?? '');
$email = nettoyerChamp($_POST['email'] ?? '');
$sujet = nettoyerChamp($_POST['sujet'] ?? '');
$message = nettoyerChamp($_POST['message'] ?? '');
$captcha = $_POST['cf-turnstile-response'] ?? '';
/*
|--------------------------------------------------------------------------
| Validation
|--------------------------------------------------------------------------
*/
$erreurs = [];
$turnstile = verifierTurnstile($captcha);
if (empty($turnstile['success'])) {
$erreurs[] = 'La vérification anti-spam a échoué. Merci de réessayer.';
}
if ($nom === '') {
$erreurs[] = 'Le nom est obligatoire.';
}
if ($email === '' || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$erreurs[] = 'L’email est obligatoire et doit être valide.';
}
if ($sujet === '') {
$erreurs[] = 'Le sujet est obligatoire.';
}
if ($message === '') {
$erreurs[] = 'Le message est obligatoire.';
}
if (!empty($erreurs)) {
$htmlErreurs = '<ul class="mb-0">';
foreach ($erreurs as $erreur) {
$htmlErreurs .= '<li>' . ecrireValeur($erreur) . '</li>';
}
$htmlErreurs .= '</ul>';
afficherPageRetour(
'Formulaire incomplet',
$htmlErreurs,
'error',
'contact.php'
);
}
/*
|--------------------------------------------------------------------------
| Contenu mail
|--------------------------------------------------------------------------
*/
$subject = 'Nouveau message de contact Find - ' . $sujet;
$fullName = $nom;
$captchaStatut = !empty($turnstile['success']) ? 'OK' : 'ECHEC';
$captchaDate = $turnstile['challenge_ts'] ?? '';
$captchaHost = $turnstile['hostname'] ?? '';
$captchaAction = $turnstile['action'] ?? '';
$htmlBody = '
<html>
<head>
<meta charset="UTF-8">
</head>
<body style="font-family:Arial,Helvetica,sans-serif; color:#162033; background:#f7f7f7; margin:0; padding:24px;">
<div style="max-width:700px; margin:0 auto; background:#ffffff; border:1px solid #e5e5e5; border-radius:16px; overflow:hidden;">
<div style="padding:24px; background:#2b94dc; color:#ffffff;">
<h1 style="margin:0; font-size:24px;">Nouveau message de contact</h1>
</div>
<div style="padding:24px;">
<p style="margin-top:0;">Un nouveau message a été envoyé depuis le formulaire de contact Find.</p>
<table style="width:100%; border-collapse:collapse; margin-bottom:20px;">
<tr>
<td style="padding:10px; border-bottom:1px solid #eeeeee; width:220px;"><strong>Nom</strong></td>
<td style="padding:10px; border-bottom:1px solid #eeeeee;">' . ecrireValeur($nom) . '</td>
</tr>
<tr>
<td style="padding:10px; border-bottom:1px solid #eeeeee;"><strong>Email</strong></td>
<td style="padding:10px; border-bottom:1px solid #eeeeee;">' . ecrireValeur($email) . '</td>
</tr>
<tr>
<td style="padding:10px;"><strong>Sujet</strong></td>
<td style="padding:10px;">' . ecrireValeur($sujet) . '</td>
</tr>
<tr>
<td style="padding:10px; border-bottom:1px solid #eeeeee;"><strong>Captcha</strong></td>
<td style="padding:10px; border-bottom:1px solid #eeeeee;">' . ecrireValeur($captchaStatut) . '</td>
</tr>
<tr>
<td style="padding:10px; border-bottom:1px solid #eeeeee;"><strong>Hostname captcha</strong></td>
<td style="padding:10px; border-bottom:1px solid #eeeeee;">' . ecrireValeur($captchaHost) . '</td>
</tr>
<tr>
<td style="padding:10px;"><strong>Date vérification captcha</strong></td>
<td style="padding:10px;">' . ecrireValeur($captchaDate) . '</td>
</tr>
</table>
<div style="padding:16px; background:#f8fafc; border:1px solid #e9eef3; border-radius:12px; white-space:pre-line;">' . nl2br(ecrireValeur($message)) . '</div>
</div>
</div>
</body>
</html>';
$textBody =
"Nouveau message de contact\n\n" .
"Nom : " . $nom . "\n" .
"Email : " . $email . "\n" .
"Sujet : " . $sujet . "\n" .
"Captcha : " . $captchaStatut . "\n" .
"Hostname captcha : " . $captchaHost . "\n" .
"Date vérification captcha : " . $captchaDate . "\n\n" .
"Message :\n" . $message . "\n";
/*
|--------------------------------------------------------------------------
| Envoi
|--------------------------------------------------------------------------
*/
$erreurMail = null;
if (envoyerMailFind($email, $fullName, $subject, $htmlBody, $textBody, $erreurMail)) {
afficherPageRetour(
'Message envoyé',
'Merci, votre message a bien été envoyé.',
'success',
'contact.php'
);
}
afficherPageRetour(
'Erreur d’envoi',
'Erreur PHPMailer : ' . ecrireValeur((string) $erreurMail),
'error',
'contact.php'
);