67 lines
2.7 KiB
PHP
67 lines
2.7 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
header('Access-Control-Allow-Origin: *');
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(204); exit; }
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') { echo json_encode(['ok'=>false,'error'=>'POST required']); exit; }
|
|
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
if (!$data) { echo json_encode(['ok'=>false,'error'=>'Invalid JSON']); exit; }
|
|
|
|
$name = trim($data['name'] ?? '');
|
|
$email = trim($data['email'] ?? '');
|
|
$company = trim($data['company'] ?? '');
|
|
$date = trim($data['date'] ?? '');
|
|
$slot = trim($data['slot'] ?? '');
|
|
$duration = intval($data['duration'] ?? 30);
|
|
$subject = trim($data['subject'] ?? 'Consultation');
|
|
$message = trim($data['message'] ?? '');
|
|
|
|
if (!$name || !$email || !$date || !$slot) {
|
|
echo json_encode(['ok'=>false,'error'=>'Champs requis: nom, email, date, créneau']);
|
|
exit;
|
|
}
|
|
|
|
// Build email
|
|
$to = 'info@weval-consulting.com';
|
|
$mail_subject = "RDV WEVAL — {$subject} — {$date} {$slot}";
|
|
$body = "Nouvelle demande de rendez-vous\n";
|
|
$body .= "========================================\n\n";
|
|
$body .= "Nom: {$name}\n";
|
|
$body .= "Email: {$email}\n";
|
|
$body .= "Entreprise: {$company}\n";
|
|
$body .= "Date: {$date} à {$slot}\n";
|
|
$body .= "Durée: {$duration} min\n";
|
|
$body .= "Sujet: {$subject}\n";
|
|
if ($message) $body .= "Message: {$message}\n";
|
|
$body .= "\n========================================\n";
|
|
$body .= "Source: weval-consulting.com/booking.html\n";
|
|
$body .= "IP: " . ($_SERVER['REMOTE_ADDR'] ?? 'unknown') . "\n";
|
|
$body .= "Date: " . date('Y-m-d H:i:s') . "\n";
|
|
|
|
$headers = "From: WEVAL Booking <noreply@weval-consulting.com>\r\n";
|
|
$headers .= "Reply-To: {$email}\r\n";
|
|
$headers .= "X-Mailer: WEVAL-Booking/1.0\r\n";
|
|
|
|
// Send via local mail()
|
|
$sent = @mail($to, $mail_subject, $body, $headers);
|
|
|
|
// Also log to file
|
|
$log = date('Y-m-d H:i:s') . " | {$name} | {$email} | {$company} | {$date} {$slot} | {$duration}min | {$subject}\n";
|
|
@file_put_contents('/var/log/weval-booking.log', $log, FILE_APPEND);
|
|
|
|
// Send confirmation to client
|
|
if ($sent) {
|
|
$conf_subject = "Confirmation — Rendez-vous WEVAL Consulting";
|
|
$conf_body = "Bonjour {$name},\n\n";
|
|
$conf_body .= "Nous avons bien reçu votre demande de rendez-vous :\n\n";
|
|
$conf_body .= "Date : {$date} à {$slot}\n";
|
|
$conf_body .= "Durée : {$duration} minutes\n";
|
|
$conf_body .= "Sujet : {$subject}\n\n";
|
|
$conf_body .= "Nous vous confirmerons le créneau sous 24h.\n\n";
|
|
$conf_body .= "Cordialement,\nWEVAL Consulting\ninfo@weval-consulting.com";
|
|
$conf_headers = "From: WEVAL Consulting <info@weval-consulting.com>\r\n";
|
|
@mail($email, $conf_subject, $conf_body, $conf_headers);
|
|
}
|
|
|
|
echo json_encode(['ok' => true, 'message' => 'Demande envoyée']);
|