Salve. Come posso fare in modo che se l'utente non riempie alcuni campi del form, nella mail inviata salti quel dato nullo e inserisca solo i campi inseriti dall'utente?
esempio: non viene inserito il campo "Provincia"
nella mail risulterà:
Nome: Mario
Cognome: Rossi
Nata/o a: Roma
Il: 25/12/1985
Via, Piazza, etc..: Via Tal De Tali 45
Via, Piazza, etc..: Via Tal De Tali 45
Città: Roma
CAP: 34666
Paese: ITALY
etc; etc....
Se invece viene inserito nella mail risulterà:
Nome: Mario
Cognome: Rossi
Nata/o a: Roma
Il: 25/12/1985
Via, Piazza, etc..: Via Tal De Tali 45
Via, Piazza, etc..: Via Tal De Tali 45
Città: Roma
Provincia: RO
CAP: 34666
Paese: ITALY
etc; etc....
Questo è tutto il codice php:
codice:
<?php
// L'INDIRIZZO DEL DESTINATARIO DELLA MAIL
$to = "amivan85@gmail.com";
// IL SOGGETTO DELLA MAIL
$subject = "Modulo Richiesta informazioni da www.xxx.xxx";
// COSTRUZIONE DEL CORPO DEL MESSAGGIO
$body = "Contenuto del modulo:\n\n";
$body .= "Nome: " . trim(stripslashes($_POST["nome"])) . "\n";
$body .= "Cognome: " . trim(stripslashes($_POST["cognome"])) . "\n";
$body .= "Nata/o a: " . trim(stripslashes($_POST["element_2"])) . "\n";
$body .= "Il: " . trim(stripslashes($_POST["element_3_2"])) . "/" . trim(stripslashes($_POST['element_3_1'])) . "/" . trim(stripslashes($_POST['element_3_3'])) . "\n";
$body .= "Indirizzo\n\n";
$body .= "Via, Piazza, etc..: " . trim(stripslashes($_POST["element_4_1"])) . "\n";
$body .= "Via, Piazza, etc..: " . trim(stripslashes($_POST["element_4_2"])) . "\n";
$body .= "Città: " . trim(stripslashes($_POST["element_4_3"])) . "\n";
$body .= "Provincia: " . trim(stripslashes($_POST["element_4_4"])) . "\n";
$body .= "CAP: " . trim(stripslashes($_POST["element_4_5"])) . "\n";
$body .= "Paese: " . trim(stripslashes($_POST["element_4_6"])) . "\n";
$body .= "Telefono: " . trim(stripslashes($_POST["telefono"])) . "-" . trim(stripslashes($_POST["telefono2"])) . "-" . trim(stripslashes($_POST["telefono3"])) . "\n";
$body .= "Mail: " . trim(stripslashes($_POST["element_6_a"])) . "\n";
$body .= "Il mio livello di ballo è!: " . trim(stripslashes($_POST["element_9_a"])) . "\n";
$body .= "Vorrei imparare questi balli: ";
$body .= trim(stripslashes($_POST["element_8_1"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_2"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_3"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_4"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_5"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_6"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_7"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_8"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_9"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_10"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_11"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_12"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_13"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_14"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_15"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_16"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_17"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_18"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_19"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_20"])) . "\n";
$body .= trim(stripslashes($_POST["element_8_21"])) . "\n";
$body .= "Altro: " . trim(stripslashes($_POST["element_7"])) . "\n";
$body .= "Ho conosciuto il sito tramite...: " . trim(stripslashes($_POST["sito"])) . trim(stripslashes($_POST["sito2"])) . trim(stripslashes($_POST["sito3"])) . trim(stripslashes($_POST["sito4"])) . trim(stripslashes($_POST["sito5"])) . "\n";
$body .= "Desidero ballare nella scuola di...: " . trim(stripslashes($_POST["element_9"])) . "\n";
$body .= "Volevo imparare a ballare da...: " . trim(stripslashes($_POST["element_1"])) . "\n";
$body .= "Ho deciso proprio adesso di iniziare a ballare perché...: " . trim(stripslashes($_POST["element_2"])) . "\n";
$body .= "Ho detto che voglio imparare a ballare ha.... E pensano che...: " . trim(stripslashes($_POST["element_3"])) . "\n";
$body .= "Vorrei venire a ballare questo numero di volte a settimana...: " . trim(stripslashes($_POST["element_4"])) . "\n";
$body .= "Mi aspetto da questa esperienza di...: " . trim(stripslashes($_POST["element_5"])) . "\n";
$body .= "Ballerò (Da solo o con qualcuno)...: " . trim(stripslashes($_POST["element_6"])) . "\n";
// INTESTAZIONI SUPPLEMENTARI
$headers = "From: Modulo Richiesta informazioni. <info@xxx.xxx>";
// INVIO DELLA MAIL
if(@mail($to, $subject, $body, $headers)) {
echo "La mail è stata inoltrata con successo.";
} else {
echo "Si sono verificati dei problemi nell'invio della mail.";
}
?>
Provincia: RO Provincia: RO