90 lines
No EOL
2.7 KiB
PHP
90 lines
No EOL
2.7 KiB
PHP
<?php
|
|
/**
|
|
* OmégaKube — Envoi formulaire de contact
|
|
*/
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Access-Control-Allow-Methods: POST, OPTIONS');
|
|
header('Access-Control-Allow-Headers: Content-Type');
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { exit; }
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
die(json_encode(['success' => false, 'error' => 'POST requis']));
|
|
}
|
|
|
|
// === CONFIG ===
|
|
$to = 'contact@omegakube.fr';
|
|
|
|
// === LECTURE ===
|
|
$input = file_get_contents('php://input');
|
|
$data = json_decode($input, true);
|
|
if (empty($data)) $data = $_POST;
|
|
if (empty($data)) {
|
|
die(json_encode(['success' => false, 'error' => 'Aucune donnée reçue']));
|
|
}
|
|
|
|
foreach ($data as $k => $v) {
|
|
$data[$k] = trim(strip_tags((string)$v));
|
|
}
|
|
|
|
// === VALIDATION ===
|
|
$errors = [];
|
|
if (empty($data['name']) || mb_strlen($data['name']) < 2) $errors[] = 'Nom invalide';
|
|
if (empty($data['email']) || !filter_var($data['email'], FILTER_VALIDATE_EMAIL)) $errors[] = 'Email invalide';
|
|
if (empty($data['message']) || mb_strlen($data['message']) < 10) $errors[] = 'Message trop court';
|
|
|
|
if ($errors) {
|
|
die(json_encode(['success' => false, 'errors' => $errors]));
|
|
}
|
|
|
|
// === HONEYPOT ===
|
|
if (!empty($data['website'])) {
|
|
die(json_encode(['success' => true, 'message' => 'Message envoyé !']));
|
|
}
|
|
|
|
// === SUJET ===
|
|
$subject = 'Omegakube form - ' . $data['name'] . ' - ' . date('H:i:s');
|
|
|
|
// === CORPS ===
|
|
$sep = str_repeat('=', 40);
|
|
|
|
$body = "OmegaKube — Nouveau message de contact\n";
|
|
$body .= $sep . "\n\n";
|
|
$body .= "Nom : " . $data['name'] . "\n";
|
|
$body .= "Email : " . $data['email'] . "\n";
|
|
$body .= "Objet : " . ($data['subject'] ?? 'Non precis') . "\n";
|
|
$body .= "\n" . $sep . "\n\n";
|
|
$body .= "MESSAGE :\n\n";
|
|
$body .= $data['message'] . "\n\n";
|
|
$body .= $sep . "\n\n";
|
|
$body .= "Repondre : " . $data['email'] . "\n";
|
|
$body .= "Recu le : " . date('d/m/Y H:i') . "\n";
|
|
$body .= "IP : " . ($_SERVER['REMOTE_ADDR'] ?? '') . "\n\n";
|
|
$body .= $sep . "\n";
|
|
$body .= "OmegaKube — omegakube.fr\n";
|
|
|
|
// === HEADERS ===
|
|
$headers = implode("\r\n", [
|
|
'MIME-Version: 1.0',
|
|
'Content-Type: text/plain; charset=UTF-8',
|
|
'From: OmegaKube <noreply@omegakube.fr>',
|
|
'Reply-To: ' . $data['email']
|
|
]);
|
|
|
|
// === ENVOI ===
|
|
$sent = mail($to, $subject, $body, $headers);
|
|
|
|
// === REPONSE ===
|
|
if ($sent) {
|
|
echo json_encode([
|
|
'success' => true,
|
|
'message' => 'Votre message a bien ete envoye ! Nous vous repondrons rapidement.'
|
|
]);
|
|
} else {
|
|
http_response_code(500);
|
|
echo json_encode([
|
|
'success' => false,
|
|
'error' => 'Erreur lors de l\'envoi. Contactez-nous directement sur Discord.'
|
|
]);
|
|
} |