false, ‘message’ => ‘Metodo non permesso’]);
exit;
}
// Recupera e sanifica i dati
$nome = trim($_POST[‘nome’] ?? ”);
$telefono = trim($_POST[‘telefono’] ?? ”);
$email = trim($_POST[‘email’] ?? ”);
$citta = trim($_POST[‘citta’] ?? ”);
$progetto = trim($_POST[‘progetto’] ?? ”);
$messaggio = trim($_POST[‘messaggio’] ?? ”);
// Validazione dati obbligatori
$errors = [];
if (empty($nome)) $errors[] = ‘Nome obbligatorio’;
if (empty($telefono)) $errors[] = ‘Telefono obbligatorio’;
if (empty($citta)) $errors[] = ‘Città obbligatoria’;
if (empty($progetto)) $errors[] = ‘Tipo progetto obbligatorio’;
// Validazione telefono
if (!empty($telefono) && !preg_match(‘/^[\d\s\+\-\(\)]{8,}$/’, $telefono)) {
$errors[] = ‘Formato telefono non valido’;
}
// Validazione email (se fornita)
if (!empty($email) && !filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = ‘Email non valida’;
}
if (!empty($errors)) {
http_response_code(400);
echo json_encode([‘success’ => false, ‘message’ => implode(‘, ‘, $errors)]);
exit;
}
// Prepara i dati per il salvataggio
$timestamp = date(‘Y-m-d H:i:s’);
$ip_address = $_SERVER[‘REMOTE_ADDR’] ?? ‘unknown’;
$user_agent = $_SERVER[‘HTTP_USER_AGENT’] ?? ‘unknown’;
// Salva in file CSV (backup locale)
$csv_data = [
$timestamp,
$nome,
$telefono,
$email,
$citta,
$progetto,
str_replace([“\n”, “\r”, “,”], [” “, ” “, “;”], $messaggio),
$ip_address
];
$csv_file = ‘contatti_vanoschi.csv’;
$csv_content = implode(‘,’, array_map(function($field) {
return ‘”‘ . str_replace(‘”‘, ‘””‘, $field) . ‘”‘;
}, $csv_data)) . “\n”;
// Crea header CSV se file non exists
if (!file_exists($csv_file)) {
$csv_header = “Timestamp,Nome,Telefono,Email,Città,Progetto,Messaggio,IP\n”;
file_put_contents($csv_file, $csv_header);
}
file_put_contents($csv_file, $csv_content, FILE_APPEND | LOCK_EX);
// Prepara email di notifica
$progetti_labels = [
‘nuovo-giardino’ => ‘Progettazione Nuovo Giardino’,
‘restyling’ => ‘Restyling Giardino Esistente’,
‘manutenzione’ => ‘Servizio Manutenzione’,
‘irrigazione’ => ‘Sistema Irrigazione’,
‘terrazzo’ => ‘Trasformazione Terrazzo’,
‘altro’ => ‘Progetto Speciale’
];
$progetto_label = $progetti_labels[$progetto] ?? $progetto;
$email_subject = “🌱 NUOVO SOPRALLUOGO: $nome – $progetto_label”;
$email_body = ”
“;
// Invia email
$headers = [
‘MIME-Version: 1.0’,
‘Content-type: text/html; charset=UTF-8’,
“From: Vanoschi Landing Page <$smtp_from>“,
“Reply-To: $email”,
“X-Mailer: PHP/” . phpversion()
];
if ($bcc_email) {
$headers[] = “Bcc: $bcc_email”;
}
$mail_sent = mail($recipient_email, $email_subject, $email_body, implode(“\r\n”, $headers));
// Risposta JSON
if ($mail_sent) {
echo json_encode([
‘success’ => true,
‘message’ => ‘Richiesta inviata con successo! Ti contatteremo entro 2 ore.’,
‘timestamp’ => $timestamp
]);
} else {
// Salvataggio riuscito ma email fallita
echo json_encode([
‘success’ => true,
‘message’ => ‘Richiesta salvata! Ti contatteremo al più presto.’,
‘warning’ => ‘Email notification failed’,
‘timestamp’ => $timestamp
]);
}
// Log per debug (opzionale)
error_log(“Vanoschi Contact: $nome ($telefono) – $progetto_label – ” . ($mail_sent ? ‘EMAIL_SENT’ : ‘EMAIL_FAILED’));
?>
🌱 VANOSCHI – Nuovo Contatto
Richiesta sopralluogo dalla landing page
⏰ RISPONDERE ENTRO 2 ORE NEGLI ORARI LAVORATIVI
👤 Dati Cliente
Nome: $nome
Telefono: $telefono
Email: ” . ($email ? “$email” : “Non fornita”) . “
Città: $citta
🏡 Progetto Richiesto
Tipo: $progetto_label
” . ($messaggio ? “Dettagli:
” . nl2br(htmlspecialchars($messaggio)) . “
📋 Prossimi Passi
- ☎️ Chiamare entro 2 ore negli orari lavorativi
- 📅 Fissare sopralluogo gratuito
- 📝 Preparare preventivo entro 24h dal sopralluogo
- 💼 Aggiornare CRM/sistema gestionale
🔍 Info Tecniche
Data/Ora: $timestamp
IP: $ip_address
Fonte: Landing Page Google Ads
Vanoschi Specialisti del Verde – Sistema automatico di gestione contatti
Questa email è stata generata automaticamente dalla landing page

