// Gestione form prenotazione RENTRI
add_action(‘admin_post_nopriv_rentri_booking’, ‘handle_rentri_booking’);
add_action(‘admin_post_rentri_booking’, ‘handle_rentri_booking’);
function handle_rentri_booking() {
// Verifica nonce per sicurezza
if (!isset($_POST[‘rentri_nonce’]) || !wp_verify_nonce($_POST[‘rentri_nonce’], ‘rentri_booking_nonce’)) {
wp_die(‘Errore di sicurezza’);
}
// Raccogli i dati
$name = sanitize_text_field($_POST[‘name’]);
$email = sanitize_email($_POST[‘email’]);
$phone = sanitize_text_field($_POST[‘phone’]);
$serviceType = sanitize_text_field($_POST[‘serviceType’]);
$message = sanitize_textarea_field($_POST[‘message’]);
// Prepara l’email
$to = ‘alberto.arfe@ecofarmatuttopartners.com’;
$subject = ‘Nuova Prenotazione RENTRI da ‘ . $name;
$body = “Nuova richiesta di consulenza RENTRI:\n\n”;
$body .= “Nome: $name\n”;
$body .= “Email: $email\n”;
$body .= “Telefono: $phone\n”;
$body .= “Servizio: $serviceType\n”;
$body .= “Messaggio: $message\n”;
$headers = array(‘Content-Type: text/plain; charset=UTF-8’);
// Invia l’email
$sent = wp_mail($to, $subject, $body, $headers);
// Redirect dopo invio
if ($sent) {
wp_redirect(add_query_arg(‘booking’, ‘success’, wp_get_referer()));
} else {
wp_redirect(add_query_arg(‘booking’, ‘error’, wp_get_referer()));
}
exit;
}