vers. 2.1.1
This commit is contained in:
59
process_contact.php.old
Normal file
59
process_contact.php.old
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
// File: process_contact.php
|
||||
|
||||
// Imposta header per JSON
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// Verifica se il modulo è stato inviato
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
// Raccolta e pulizia dei dati
|
||||
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING);
|
||||
$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
|
||||
$subject = filter_input(INPUT_POST, 'subject', FILTER_SANITIZE_STRING);
|
||||
$message = filter_input(INPUT_POST, 'message', FILTER_SANITIZE_STRING);
|
||||
|
||||
// Validazione dei dati
|
||||
$errors = [];
|
||||
|
||||
if (empty($name)) {
|
||||
$errors[] = "Il nome è richiesto";
|
||||
}
|
||||
|
||||
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$errors[] = "Email non valida";
|
||||
}
|
||||
|
||||
if (empty($subject)) {
|
||||
$errors[] = "L'oggetto è richiesto";
|
||||
}
|
||||
|
||||
if (empty($message)) {
|
||||
$errors[] = "Il messaggio è richiesto";
|
||||
}
|
||||
|
||||
// Se non ci sono errori, procedi con l'invio della mail
|
||||
if (empty($errors)) {
|
||||
// Destinatario
|
||||
$to = "info@tuoaggregatore.it";
|
||||
|
||||
// Intestazioni
|
||||
$headers = "From: $name <$email>" . "\r\n";
|
||||
$headers .= "Reply-To: $email" . "\r\n";
|
||||
$headers .= "X-Mailer: PHP/" . phpversion();
|
||||
|
||||
// Prova a inviare l'email
|
||||
$success = mail($to, $subject, $message, $headers);
|
||||
|
||||
if ($success) {
|
||||
echo json_encode(['success' => true, 'message' => 'Messaggio inviato con successo']);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => 'Impossibile inviare il messaggio']);
|
||||
}
|
||||
} else {
|
||||
// Restituisci errori di validazione
|
||||
echo json_encode(['success' => false, 'message' => implode(', ', $errors)]);
|
||||
}
|
||||
} else {
|
||||
// Se qualcuno prova ad accedere direttamente a questa pagina
|
||||
echo json_encode(['success' => false, 'message' => 'Metodo non consentito']);
|
||||
}
|
||||
Reference in New Issue
Block a user