Buongiorno a tutti, ho bisogno di un aiuto per capire per quale motivo non mi funziona un semplice script php sul server. Il server in questione è "ARUBA", ed il mio spazio web ha un hosting linux ed è configurato per la funzione "php mail". Ho inserito un form html in una pagina del mio sito per raccogliere dati, questo form è processato in locale con javascript, se il modulo è compilato correttamente javascript invia i dati allo script "mail.php" sul server che dovrebbe rispedirmeli formattati alla mia casella di posta. Invece succede che il server mi da un errore quando cerca di eseguire lo script, ma non capisco dove ho sbagliato.
Vi posto la pagina html che al suo interno contiene il form e il javascript, e lo script php che ho sul server:
SCRIPT "MAIL
HP":
<?php
// L'INDIRIZZO DEL DESTINATARIO DELLA MAIL
$to = "s.rossetti5@virgilio.it";
// IL SOGGETTO DELLA MAIL
$subject = "Modulo proveniente dal sito www.gls-autonoleggio.it";
// COSTRUIAMO IL CORPO DEL MESSAGGIO
$body = "Contenuto del modulo:\n\n";
$body .= "Nome: " . trim(stripslashes($_POST["nome"])) . "\n";
$body .= "Cognome: " . trim(stripslashes($_POST["cognome"])) . "\n";
$body .= "N° persone: " . trim(stripslashes($_POST["persone"])) . "\n";
$body .= "N° bagagl: " . trim(stripslashes($_POST["bagagli"])) . "\n";
$body .= "arrivo: " . trim(stripslashes($_POST["arrivo"])) . "\n";
$body .= "sigla: " . trim(stripslashes($_POST["sigla"])) . "\n";
$body .= "data: " . trim(stripslashes($_POST["data"])) . "\n";
$body .= "ora: " . trim(stripslashes($_POST["ora"])) . "\n";
$body .= "telefono: " . trim(stripslashes($_POST["telefono"])) . "\n";
$body .= "email: " . trim(stripslashes($_POST["email"])) . "\n";
$body .= "destinazione: " . trim(stripslashes($_POST["destinazione"])) . "\n";
$body .= "pagamento: " . trim(stripslashes($_POST["pagamento"])) . "\n";
$body .= "messaggio: " . trim(stripslashes($_POST["firma"])) . "\n";
// INTESTAZIONI SUPPLEMENTARI
$headers = "From: Modulo utenti<modulo@sito.it>";
// INVIO DELLA MAIL
if(@mail($to, $subject, $body, $headers)) { // SE L'INOLTRO È ANDATO A BUON FINE...
echo "La mail è stata inoltrata con successo.";
} else {// ALTRIMENTI...
echo "Si sono verificati dei problemi nell'invio della mail.";
}
?>
FINE SCRIPT PHP.
INIZIO PAGINA HTML CON FORM (HO INSERITO SOLO LA PARTE COL FORM):
<table align="center" border="1">
<form method="post" name="modulo">
<tr>
<td colspan="2" align="center"><b>Registrazione al servizio<br>Tutti i campi sono obbligatori</b></td>
</tr>
<tr>
<td><b>Nome</b></td>
<td><input type="text" name="nome"></td>
</tr>
<tr>
<td><b>Cognome</b></td>
<td><input type="text" name="cognome"></td>
</tr>
<tr>
<td><b>N° persone</b></td>
<td><input type="text" name="persone"></td>
</tr>
<tr>
<td><b>N° bagagli</b></td>
<td><input type="text" name="bagagli"></td>
</tr>
<tr>
<td><b>Arrivo a:</b></td>
<td>
<select name="arrivo">
<option>- Seleziona il luogo di arrivo -</option>
<option value="Fiumicino">Fiumicino </option>
<option value="Ciampino">Ciampino</option>
<option value="Civitavecchia">Civitavecchia</option>
<option value="St. Termini">St. Termini</option>
<option value="Altro">Altro</option>
</select>
</td>
</tr>
<tr>
<td><b>Sigla aereo, nave, treno</b></td>
<td><input type="text" name="sigla"></td>
</tr>
<tr>
<td><b>Data di arrivo (es: 12/04/2010)</b></td>
<td><input type="text" name="data"></td>
</tr>
<tr>
<td><b>presunta ora arrivo</b></td>
<td><input type="text" name="ora"></td>
</tr>
<tr>
<td><b>Telefono (senza spazi nè simboli)</b></td>
<td><input type="text" name="telefono"></td>
</tr>
<tr>
<td><b>Email</b></td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td><b>Inserire destinazione</b></td>
<td><input type="text" name="destinazione"></td>
</tr>
<tr>
<td><b>Tipo pagamento</b></td>
<td>
<select name="pagamento">
<option value="contanti">Contanti</option>
<option value="cdc">Carta di credito</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<textarea name="firma" rows="5" cols="32">Inserisci messaggio</textarea>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="button" value="Invia" onClick="Modulo()">
</td>
</tr>
</form>
</table>
<script language="javascript">
<!--
function Modulo() {
// Variabili associate ai campi del modulo
var nome = document.modulo.nome.value;
var cognome = document.modulo.cognome.value;
var persone = document.modulo.persone.value;
var bagagli = document.modulo.bagagli.value;
var arrivo = document.modulo.arrivo.options[document.modulo.arrivo.selectedIndex].value;
var sigla = document.modulo.sigla.value;
var data = document.modulo.data.value;
var ora = document.modulo.ora.value;
var telefono = document.modulo.telefono.value;
var email = document.modulo.email.value;
var destinazione = document.modulo.destinazione.value;
var pagamento = document.modulo.pagamento.options[document.modulo.pagamento.selectedIndex].value;
// Espressione regolare dell'email
var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
//Effettua il controllo sul campo NOME
if ((nome == "") || (nome == "undefined")) {
alert("Il campo Nome è obbligatorio.");
document.modulo.nome.focus();
return false;
}
//Effettua il controllo sul campo COGNOME
else if ((cognome == "") || (cognome == "undefined")) {
alert("Il campo Cognome è obbligatorio.");
document.modulo.cognome.focus();
return false;
}
//Effettua il controllo sul campo PERSONE
else if ((persone == "") || (persone == "undefined")) {
alert("Il campo N° persone è obbligatorio.");
document.modulo.persone.focus();
return false;
}
//Effettua il controllo sul campo BAGAGLI
else if ((bagagli == "") || (bagagli == "undefined")) {
alert("Il campo N° bagagli è obbligatorio.");
document.modulo.bagagli.focus();
return false;
}
//Effettua il controllo sul campo ARRIVO
else if ((arrivo == "") || (arrivo == "undefined")) {
alert("Il campo arrivo è obbligatorio.");
document.modulo.arrivo.focus();
return false;
}
//Effettua il controllo sul campo SIGLA
else if ((sigla == "") || (sigla == "undefined")) {
alert("Il campo sigla è obbligatorio.");
document.modulo.sigla.focus();
return false;
}
//Effettua il controllo sul campo DATA
else if (document.modulo.data.value.substring(2,3) != "/" ||
document.modulo.data.value.substring(5,6) != "/" ||
isNaN(document.modulo.data.value.substring(0,2)) ||
isNaN(document.modulo.data.value.substring(3,5)) ||
isNaN(document.modulo.data.value.substring(6,10))) {
alert("Inserire data arrivo in formato gg/mm/aaaa");
document.modulo.data.value = "";
document.modulo.data.focus();
return false;
}
else if (document.modulo.data.value.substring(0,2) > 31) {
alert("Impossibile utilizzare un valore superiore a 31 per i giorni");
document.modulo.data.select();
return false;
}
else if (document.modulo.data.value.substring(3,5) > 12) {
alert("Impossibile utilizzare un valore superiore a 12 per i mesi");
document.modulo.data.value = "";
document.modulo.data.focus();
return false;
}
else if (document.modulo.data.value.substring(6,10) < 1900) {
alert("Impossibile utilizzare un valore inferiore a 1900 per l'anno");
document.modulo.data.value = "";
document.modulo.data.focus();
return false;
}
//Effettua il controllo sul campo ORA
else if ((ora == "") || (ora == "undefined")) {
alert("Il campo ora è obbligatorio.");
document.modulo.ora.focus();
return false;
}
//Effettua il controllo sul campo TELEFONO
else if ((isNaN(telefono)) || (telefono == "") || (telefono == "undefined")) {
alert("Il campo Telefono è numerico ed obbligatorio.");
document.modulo.telefono.value = "";
document.modulo.telefono.focus();
return false;
}
else if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
alert("Inserire un indirizzo email corretto.");
document.modulo.email.select();
return false;
}
//Effettua il controllo sul campo DESTINAZIONE
else if ((destinazione == "") || (destinazione == "undefined")) {
alert("Il campo destinazione è obbligatorio.");
document.modulo.destinazione.focus();
return false;
}
//Effettua il controllo sul campo TIPO PAGAMENTO
else if ((pagamento == "") || (pagamento == "undefined")) {
alert("Il campo pagamento è obbligatorio.");
document.modulo.pagamento.focus();
return false;
}
//INVIA IL MODULO
else {
document.modulo.action = "./mail.php";
document.modulo.submit();
}
}
//-->
</script>
</div>
</div>
</div>
</body>
</html>
P.S. Potete anche verificare il non funzionamento dello script PHP andando sul mio sito "www.gls-autonoleggio.it", compilando il form nella sezione "prenotazioni" provando ad inviarlo.
Vi posto la pagina html che al suo interno contiene il form e il javascript, e lo script php che ho sul server:
SCRIPT "MAIL

<?php
// L'INDIRIZZO DEL DESTINATARIO DELLA MAIL
$to = "s.rossetti5@virgilio.it";
// IL SOGGETTO DELLA MAIL
$subject = "Modulo proveniente dal sito www.gls-autonoleggio.it";
// COSTRUIAMO IL CORPO DEL MESSAGGIO
$body = "Contenuto del modulo:\n\n";
$body .= "Nome: " . trim(stripslashes($_POST["nome"])) . "\n";
$body .= "Cognome: " . trim(stripslashes($_POST["cognome"])) . "\n";
$body .= "N° persone: " . trim(stripslashes($_POST["persone"])) . "\n";
$body .= "N° bagagl: " . trim(stripslashes($_POST["bagagli"])) . "\n";
$body .= "arrivo: " . trim(stripslashes($_POST["arrivo"])) . "\n";
$body .= "sigla: " . trim(stripslashes($_POST["sigla"])) . "\n";
$body .= "data: " . trim(stripslashes($_POST["data"])) . "\n";
$body .= "ora: " . trim(stripslashes($_POST["ora"])) . "\n";
$body .= "telefono: " . trim(stripslashes($_POST["telefono"])) . "\n";
$body .= "email: " . trim(stripslashes($_POST["email"])) . "\n";
$body .= "destinazione: " . trim(stripslashes($_POST["destinazione"])) . "\n";
$body .= "pagamento: " . trim(stripslashes($_POST["pagamento"])) . "\n";
$body .= "messaggio: " . trim(stripslashes($_POST["firma"])) . "\n";
// INTESTAZIONI SUPPLEMENTARI
$headers = "From: Modulo utenti<modulo@sito.it>";
// INVIO DELLA MAIL
if(@mail($to, $subject, $body, $headers)) { // SE L'INOLTRO È ANDATO A BUON FINE...
echo "La mail è stata inoltrata con successo.";
} else {// ALTRIMENTI...
echo "Si sono verificati dei problemi nell'invio della mail.";
}
?>
FINE SCRIPT PHP.
INIZIO PAGINA HTML CON FORM (HO INSERITO SOLO LA PARTE COL FORM):
<table align="center" border="1">
<form method="post" name="modulo">
<tr>
<td colspan="2" align="center"><b>Registrazione al servizio<br>Tutti i campi sono obbligatori</b></td>
</tr>
<tr>
<td><b>Nome</b></td>
<td><input type="text" name="nome"></td>
</tr>
<tr>
<td><b>Cognome</b></td>
<td><input type="text" name="cognome"></td>
</tr>
<tr>
<td><b>N° persone</b></td>
<td><input type="text" name="persone"></td>
</tr>
<tr>
<td><b>N° bagagli</b></td>
<td><input type="text" name="bagagli"></td>
</tr>
<tr>
<td><b>Arrivo a:</b></td>
<td>
<select name="arrivo">
<option>- Seleziona il luogo di arrivo -</option>
<option value="Fiumicino">Fiumicino </option>
<option value="Ciampino">Ciampino</option>
<option value="Civitavecchia">Civitavecchia</option>
<option value="St. Termini">St. Termini</option>
<option value="Altro">Altro</option>
</select>
</td>
</tr>
<tr>
<td><b>Sigla aereo, nave, treno</b></td>
<td><input type="text" name="sigla"></td>
</tr>
<tr>
<td><b>Data di arrivo (es: 12/04/2010)</b></td>
<td><input type="text" name="data"></td>
</tr>
<tr>
<td><b>presunta ora arrivo</b></td>
<td><input type="text" name="ora"></td>
</tr>
<tr>
<td><b>Telefono (senza spazi nè simboli)</b></td>
<td><input type="text" name="telefono"></td>
</tr>
<tr>
<td><b>Email</b></td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td><b>Inserire destinazione</b></td>
<td><input type="text" name="destinazione"></td>
</tr>
<tr>
<td><b>Tipo pagamento</b></td>
<td>
<select name="pagamento">
<option value="contanti">Contanti</option>
<option value="cdc">Carta di credito</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<textarea name="firma" rows="5" cols="32">Inserisci messaggio</textarea>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="button" value="Invia" onClick="Modulo()">
</td>
</tr>
</form>
</table>
<script language="javascript">
<!--
function Modulo() {
// Variabili associate ai campi del modulo
var nome = document.modulo.nome.value;
var cognome = document.modulo.cognome.value;
var persone = document.modulo.persone.value;
var bagagli = document.modulo.bagagli.value;
var arrivo = document.modulo.arrivo.options[document.modulo.arrivo.selectedIndex].value;
var sigla = document.modulo.sigla.value;
var data = document.modulo.data.value;
var ora = document.modulo.ora.value;
var telefono = document.modulo.telefono.value;
var email = document.modulo.email.value;
var destinazione = document.modulo.destinazione.value;
var pagamento = document.modulo.pagamento.options[document.modulo.pagamento.selectedIndex].value;
// Espressione regolare dell'email
var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
//Effettua il controllo sul campo NOME
if ((nome == "") || (nome == "undefined")) {
alert("Il campo Nome è obbligatorio.");
document.modulo.nome.focus();
return false;
}
//Effettua il controllo sul campo COGNOME
else if ((cognome == "") || (cognome == "undefined")) {
alert("Il campo Cognome è obbligatorio.");
document.modulo.cognome.focus();
return false;
}
//Effettua il controllo sul campo PERSONE
else if ((persone == "") || (persone == "undefined")) {
alert("Il campo N° persone è obbligatorio.");
document.modulo.persone.focus();
return false;
}
//Effettua il controllo sul campo BAGAGLI
else if ((bagagli == "") || (bagagli == "undefined")) {
alert("Il campo N° bagagli è obbligatorio.");
document.modulo.bagagli.focus();
return false;
}
//Effettua il controllo sul campo ARRIVO
else if ((arrivo == "") || (arrivo == "undefined")) {
alert("Il campo arrivo è obbligatorio.");
document.modulo.arrivo.focus();
return false;
}
//Effettua il controllo sul campo SIGLA
else if ((sigla == "") || (sigla == "undefined")) {
alert("Il campo sigla è obbligatorio.");
document.modulo.sigla.focus();
return false;
}
//Effettua il controllo sul campo DATA
else if (document.modulo.data.value.substring(2,3) != "/" ||
document.modulo.data.value.substring(5,6) != "/" ||
isNaN(document.modulo.data.value.substring(0,2)) ||
isNaN(document.modulo.data.value.substring(3,5)) ||
isNaN(document.modulo.data.value.substring(6,10))) {
alert("Inserire data arrivo in formato gg/mm/aaaa");
document.modulo.data.value = "";
document.modulo.data.focus();
return false;
}
else if (document.modulo.data.value.substring(0,2) > 31) {
alert("Impossibile utilizzare un valore superiore a 31 per i giorni");
document.modulo.data.select();
return false;
}
else if (document.modulo.data.value.substring(3,5) > 12) {
alert("Impossibile utilizzare un valore superiore a 12 per i mesi");
document.modulo.data.value = "";
document.modulo.data.focus();
return false;
}
else if (document.modulo.data.value.substring(6,10) < 1900) {
alert("Impossibile utilizzare un valore inferiore a 1900 per l'anno");
document.modulo.data.value = "";
document.modulo.data.focus();
return false;
}
//Effettua il controllo sul campo ORA
else if ((ora == "") || (ora == "undefined")) {
alert("Il campo ora è obbligatorio.");
document.modulo.ora.focus();
return false;
}
//Effettua il controllo sul campo TELEFONO
else if ((isNaN(telefono)) || (telefono == "") || (telefono == "undefined")) {
alert("Il campo Telefono è numerico ed obbligatorio.");
document.modulo.telefono.value = "";
document.modulo.telefono.focus();
return false;
}
else if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
alert("Inserire un indirizzo email corretto.");
document.modulo.email.select();
return false;
}
//Effettua il controllo sul campo DESTINAZIONE
else if ((destinazione == "") || (destinazione == "undefined")) {
alert("Il campo destinazione è obbligatorio.");
document.modulo.destinazione.focus();
return false;
}
//Effettua il controllo sul campo TIPO PAGAMENTO
else if ((pagamento == "") || (pagamento == "undefined")) {
alert("Il campo pagamento è obbligatorio.");
document.modulo.pagamento.focus();
return false;
}
//INVIA IL MODULO
else {
document.modulo.action = "./mail.php";
document.modulo.submit();
}
}
//-->
</script>
</div>
</div>
</div>
</body>
</html>
P.S. Potete anche verificare il non funzionamento dello script PHP andando sul mio sito "www.gls-autonoleggio.it", compilando il form nella sezione "prenotazioni" provando ad inviarlo.