162 lines
5.6 KiB
PHP
162 lines
5.6 KiB
PHP
<?php
|
|
/**
|
|
* Gestione Form Contatti
|
|
*
|
|
* Riceve le richieste di contatto per lezioni live e invia email all'admin
|
|
*/
|
|
|
|
require_once 'includes/config.php';
|
|
require_once 'includes/functions.php';
|
|
|
|
session_start();
|
|
|
|
// Verifica che sia una richiesta POST
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
header('Location: index.php');
|
|
exit;
|
|
}
|
|
|
|
// Recupera e sanitizza i dati
|
|
$name = sanitize_input($_POST['name'] ?? '');
|
|
$email = sanitize_input($_POST['email'] ?? '');
|
|
$phone = sanitize_input($_POST['phone'] ?? '');
|
|
$message = sanitize_input($_POST['message'] ?? '');
|
|
|
|
// Validazione
|
|
$errors = [];
|
|
|
|
if (empty($name)) {
|
|
$errors[] = 'Il nome è obbligatorio';
|
|
}
|
|
|
|
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
|
$errors[] = 'Email non valida';
|
|
}
|
|
|
|
if (empty($message)) {
|
|
$errors[] = 'Il messaggio è obbligatorio';
|
|
}
|
|
|
|
// Se ci sono errori, torna indietro
|
|
if (!empty($errors)) {
|
|
set_flash_message('error', implode('. ', $errors));
|
|
header('Location: index.php#contact');
|
|
exit;
|
|
}
|
|
|
|
// Prepara email per l'amministratore
|
|
$subject = "Nuova Richiesta Lezione Live - " . SITE_NAME;
|
|
|
|
$email_body = "
|
|
<html>
|
|
<head>
|
|
<style>
|
|
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
|
|
.container { max-width: 600px; margin: 0 auto; padding: 20px; background: #f8f9fa; }
|
|
.header { background: #4A90E2; color: white; padding: 20px; text-align: center; border-radius: 8px 8px 0 0; }
|
|
.content { background: white; padding: 20px; border-radius: 0 0 8px 8px; }
|
|
.info-row { margin: 15px 0; padding: 10px; background: #e8f4f8; border-left: 4px solid #4A90E2; }
|
|
.label { font-weight: bold; color: #4A90E2; }
|
|
.message-box { background: #f8f9fa; padding: 15px; border-radius: 4px; margin-top: 15px; }
|
|
.footer { text-align: center; margin-top: 20px; color: #666; font-size: 12px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class='container'>
|
|
<div class='header'>
|
|
<h2 style='margin: 0;'>📅 Nuova Richiesta Lezione Live</h2>
|
|
</div>
|
|
<div class='content'>
|
|
<p>Hai ricevuto una nuova richiesta di contatto per una lezione live:</p>
|
|
|
|
<div class='info-row'>
|
|
<span class='label'>👤 Nome:</span> " . htmlspecialchars($name) . "
|
|
</div>
|
|
|
|
<div class='info-row'>
|
|
<span class='label'>📧 Email:</span> <a href='mailto:" . htmlspecialchars($email) . "'>" . htmlspecialchars($email) . "</a>
|
|
</div>
|
|
|
|
" . (!empty($phone) ? "
|
|
<div class='info-row'>
|
|
<span class='label'>📱 Telefono:</span> <a href='tel:" . htmlspecialchars($phone) . "'>" . htmlspecialchars($phone) . "</a>
|
|
</div>
|
|
" : "") . "
|
|
|
|
<div class='message-box'>
|
|
<p class='label'>💬 Messaggio:</p>
|
|
<p>" . nl2br(htmlspecialchars($message)) . "</p>
|
|
</div>
|
|
|
|
<p style='margin-top: 20px; padding-top: 20px; border-top: 1px solid #e0e0e0;'>
|
|
<strong>Azioni suggerite:</strong><br>
|
|
• Rispondi direttamente via email<br>
|
|
" . (!empty($phone) ? "• Contatta telefonicamente al numero indicato<br>" : "") . "
|
|
• Verifica disponibilità sul calendario
|
|
</p>
|
|
</div>
|
|
<div class='footer'>
|
|
Inviato automaticamente da " . SITE_NAME . "<br>
|
|
" . date('d/m/Y H:i') . "
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
";
|
|
|
|
// Invia email all'amministratore
|
|
if (send_email(ADMIN_EMAIL, $subject, $email_body)) {
|
|
// Email di conferma al mittente (opzionale)
|
|
$confirm_subject = "Richiesta Ricevuta - " . SITE_NAME;
|
|
|
|
$confirm_body = "
|
|
<html>
|
|
<head>
|
|
<style>
|
|
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
|
|
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
|
|
.header { background: #4A90E2; color: white; padding: 20px; text-align: center; border-radius: 8px 8px 0 0; }
|
|
.content { background: #f8f9fa; padding: 20px; border-radius: 0 0 8px 8px; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class='container'>
|
|
<div class='header'>
|
|
<h2 style='margin: 0;'>✅ Richiesta Ricevuta</h2>
|
|
</div>
|
|
<div class='content'>
|
|
<p>Ciao <strong>" . htmlspecialchars($name) . "</strong>,</p>
|
|
|
|
<p>Grazie per aver richiesto informazioni sulle nostre lezioni live!</p>
|
|
|
|
<p>Ho ricevuto il tuo messaggio e ti risponderò il prima possibile, generalmente entro 24 ore.</p>
|
|
|
|
<p style='background: white; padding: 15px; border-left: 4px solid #4A90E2; margin: 20px 0;'>
|
|
<strong>Il tuo messaggio:</strong><br>
|
|
" . nl2br(htmlspecialchars($message)) . "
|
|
</p>
|
|
|
|
<p>Nel frattempo, puoi esplorare le nostre videolezioni disponibili sul sito.</p>
|
|
|
|
<p>A presto,<br>
|
|
<strong>" . SITE_NAME . "</strong></p>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
";
|
|
|
|
send_email($email, $confirm_subject, $confirm_body);
|
|
|
|
// Log attività
|
|
log_activity(null, 'contact_form', "Richiesta contatto da: $name ($email)");
|
|
|
|
set_flash_message('success', '✅ Messaggio inviato con successo! Ti risponderemo al più presto.');
|
|
} else {
|
|
set_flash_message('error', '❌ Errore durante l\'invio del messaggio. Riprova più tardi o contattaci direttamente via email.');
|
|
}
|
|
|
|
header('Location: index.php#contact');
|
|
exit;
|
|
?>
|