Ciao a tutti,
ho un form che avevo fatto tempo fa che nonostante i controlli javascript e php viene inviato vuoto al passaggio di motori di ricerca sul sito. Avete idea di quale sia il problema o cosa devo aggiungere?
Ecco la index.php:
Codice PHP:
<?php
session_start();
$_SESSION['nome']=$_POST['nome'];
$_SESSION['email']=$_POST['email'];
$_SESSION['messaggio']=$_POST['messaggio'];
$_SESSION['ora']=$_POST['ora'];
$_SESSION['data']=$_POST['data'];
$_SESSION['referer']=$_POST['referer'];
$_SESSION['ipaddress']=$_POST['ipaddress'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Modulo contatti</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="stylesheet.css" rel="stylesheet" type="text/css" media="all" />
<script language ="javascript" type="text/javascript">
function controllo(){
with(document.modulo) {
if(nome.value=="") {
alert("Non hai compilato il campo nome");
nome.focus();
return false;
}
if(email.value=="") {
alert("Non hai compilato il campo email");
email.focus();
return false;
}
if(messaggio.value=="") {
alert("Non hai compilato il campo messaggio");
messaggio.focus();
return false;
}
}
return true;
}
function controllo_mail(indirizzo) {
if (window.RegExp)
{
var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
var regnv = new RegExp(nonvalido);
var regv = new RegExp(valido);
if (!regnv.test(indirizzo) && regv.test(indirizzo))
return true;
return false;
}
else
{
if(indirizzo.indexOf("@") >= 0)
return true;
return false;
}
}
</script>
</head>
<body>
<form name="modulo" id="modulo" onsubmit="return controllo();" method="post" action="invia.php">
<table border="0" cellpadding="3" cellspacing="5" align="center">
<tr>
<td class="form" width="100">Nome:</td>
<td><input type="text" name="nome" size="50" /></td>
</tr>
<tr>
<td class="form">Email:</td>
<td><input type="text" name="email" size="50" onblur="if (controllo_mail(this.value)==false){alert('Indirizzo email errato');};" /></td>
</tr>
<tr>
<td class="form">Messaggio: </td>
<td><textarea name="messaggio" rows="12" cols="50"></textarea></td>
</tr>
</table>
<?php
$ora = date ("h:i:s A");
$data = date ("d:m:Y");
echo "<input type=\"hidden\" name=\"ora\" value=\"$ora\" />";
echo "<input type=\"hidden\" name=\"data\" value=\"$data\" />";
if(isset($_SERVER["HTTP_X_FORWARDED_FOR"])){
if ($_SERVER["HTTP_X_FORWARDED_FOR"] == "") {
$ipnumb = getenv("REMOTE_ADDR");
} else {
$ipnumb = getenv("HTTP_X_FORWARDED_FOR");
}
} else {
$ipnumb = getenv("REMOTE_ADDR");
}
echo "<input type=\"hidden\" name=\"ipaddress\" value=\"$ipnumb\" />";
echo "<input type=\"hidden\" name=\"referer\" value=\"$_SERVER[HTTP_REFERER]\" />";
?>
<div align="center"><input type="submit" name="submit" value="Invia" class="pulsante" onmouseOut="this.className='pulsante'" onmouseover="this.className='pulsanteon'" /> <input type="reset" name="reset" value="Cancella" class="pulsante" onmouseOut="this.className='pulsante'" onmouseover="this.className='pulsanteon'" />
Informativa sul trattamento dei dati personali ai sensi dell'art. 13 del D.Lgs. 196/2003</div>
</form>
</body>
</html>
e invia.php:
Codice PHP:
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Modulo contatti</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="stylesheet.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
<div align="center" class="form">
<?php
// L’INDIRIZZO DEL DESTINATARIO DELLA MAIL
$to = "info@email.it";
// IL SOGGETTO DELLA MAIL
$subject ="Modulo Contatti";
// COSTRUZIONE DEL CORPO DEL MESSAGGIO
$body = "Dati:\n\n";
$body .= "Nome: " . trim(stripslashes($_POST["nome"])) . "\n";
$body .= "Email: " . trim(stripslashes($_POST["email"])) . "\n";
$body .= "Messaggio: " . trim(stripslashes($_POST["messaggio"])) . "\n";
$body .= "Data: " . trim(stripslashes($_POST["data"])) . "\n";
$body .= "Ora: " . trim(stripslashes($_POST["ora"])) . "\n";
$body .= "Numero IP: " . trim(stripslashes($_POST["ipaddress"])) . "\n";
$body .= "Referrer: " . trim(stripslashes($_POST["referer"])) . "\n";
// INTESTAZIONI SUPPLEMENTARI
$headers = "From: " . trim(stripslashes($_POST["email"])) . "\n";
// INVIO DELLA MAIL
if(mail($to, $subject, $body, $headers)) { // SE L’INOLTRO E’ ANDATO A BUON FINE…
echo "Grazie per aver compilato il modulo.
Sarai contattato appena possibile.";
} else {// ALTRIMENTI…
echo "Si sono verificati dei problemi nell’invio del modulo.";
}
?>
</div>
</body>
</html>