Allora questa è la mia pagina1form.html
[/PHP]
<title>Documento senza titolo</title>
<style type="text/css">
<!--
body {
background-image: url(log_h.gif);
}
.Stile1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
color: #333333;
}
.Stile2 {font-size: small}
-->
</style>
<script language="javascript">
<!--
function Modulo() {
// Variabili associate ai campi del modulo
var nome = document.modulo.nome.value;
var cognome = document.modulo.cognome.value;
var nickname = document.modulo.nickname.value;
var password = document.modulo.password.value;
var conferma = document.modulo.conferma.value;
var nascita = document.modulo.nascita.value;
var citta = document.modulo.citta.options[document.modulo.citta.selectedIndex].value;
var indirizzo = document.modulo.indirizzo.value;
var telefono = document.modulo.telefono.value;
var email = document.modulo.email.value;
var homepage = document.modulo.homepage.value;
var firma = document.modulo.firma.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 NICKNAME
else if ((nickname == "") || (nickname == "undefined")) {
alert("Il campo Nickname è obbligatorio.");
document.modulo.nickname.focus();
return false;
}
//Effettua il controllo sul campo PASSWORD
else if ((password == "") || (password == "undefined")) {
alert("Il campo Password è obbligatorio.");
document.modulo.password.focus();
return false;
}
//Effettua il controllo sul campo CONFERMA PASSWORD
else if ((conferma == "") || (conferma == "undefined")) {
alert("Il campo Conferma password è obbligatorio.");
document.modulo.conferma.focus();
return false;
}
//Verifica l'uguaglianza tra i campi PASSWORD e CONFERMA PASSWORD
else if (password != conferma) {
alert("La password confermata è diversa da quella scelta, controllare.");
document.modulo.conferma.value = "";
document.modulo.conferma.focus();
return false;
}
//Effettua il controllo sul campo DATA DI NASCITA
else if (document.modulo.nascita.value.substring(2,3) != "/" ||
document.modulo.nascita.value.substring(5,6) != "/" ||
isNaN(document.modulo.nascita.value.substring(0,2) ) ||
isNaN(document.modulo.nascita.value.substring(3,5) ) ||
isNaN(document.modulo.nascita.value.substring(6,10 ))) {
alert("Inserire nascita in formato gg/mm/aaaa");
document.modulo.nascita.value = "";
document.modulo.nascita.focus();
return false;
}
else if (document.modulo.nascita.value.substring(0,2) > 31) {
alert("Impossibile utilizzare un valore superiore a 31 per i giorni");
document.modulo.nascita.select();
return false;
}
else if (document.modulo.nascita.value.substring(3,5) > 12) {
alert("Impossibile utilizzare un valore superiore a 12 per i mesi");
document.modulo.nascita.value = "";
document.modulo.nascita.focus();
return false;
}
else if (document.modulo.nascita.value.substring(6,10) < 1900) {
alert("Impossibile utilizzare un valore inferiore a 1900 per l'anno");
document.modulo.nascita.value = "";
document.modulo.nascita.focus();
return false;
}
//Effettua il controllo sul campo CITTA'
else if ((citta == "") || (citta == "undefined")) {
alert("Il campo Città è obbligatorio.");
document.modulo.citta.focus();
return false;
}
//Effettua il controllo sul campo INDIRIZZO
else if ((indirizzo == "") || (indirizzo == "undefined")) {
alert("Il campo Indirizzo è obbligatorio.");
document.modulo.indirizzo.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 HOMEPAGE
else if ((homepage == "") || (homepage == "undefined") || (homepage.indexOf("http://") == (-1))) {
alert("Il campo Homepage non può essere privo di http://");
document.modulo.homepage.value = "http://";
document.modulo.homepage.select();
return false;
}
//Effettua il controllo sul campo FIRMA
else if ((firma == "") || (firma == "undefined") || (firma.indexOf("Inserisci qui il tuo slogan!") != (-1))) {
alert("Il campo Firma è obbligatorio e non si può inserire la scritta predefinita.");
document.modulo.firma.focus();
return false;
}
//INVIA IL MODULO
else {
document.modulo.action ="/pagina2.php";
document.modulo.submit();
}
}
//-->
</script>
</head>
<body>
<table border="1" align="center" bgcolor="#FF7F50" >
<form action="/pagina2.php" method="post" name="modulo" >
<tr>
<td colspan="2" align="center" height="45"><span class="Stile1">Registrazione</span></td>
</tr>
<tr>
<td width="389"><b class="Stile1 Stile2">Nome[/b]</td>
<td width="170"><input name="nome" type="text" maxlength="30"></td>
</tr>
<tr>
<td><b class="Stile1 Stile2">Cognome[/b]</td>
<td><input name="cognome" type="text" maxlength="30"></td>
</tr>
<tr>
<td>Nickname</td>
<td><input name="nickname" type="text" maxlength="15"></td>
</tr>
<tr>
<td>Password</td>
<td><input name="password" type="password" maxlength="15"></td>
</tr>
<tr>
<td>Conferma password</td>
<td><input name="conferma" type="password" maxlength="15"></td>
</tr>
<tr>
<td>Data di nascita (es: 12/04/1978)</td>
<td><input type="text" name="nascita"></td>
</tr>
<tr>
<td>Sesso</td>
<td>
<input type="radio" name="sesso" value="M" checked>M
<input type="radio" name="sesso" value="F">F
</td>
</tr>
<tr>
<td>Cittá</td>
<td>
<select name="citta">
<option>- Seleziona la tua città -</option>
<option value="Roma">Roma</option>
<option value="Milano">Milano</option>
<option value="Napoli">Napoli</option>
<option value="Firenze">Firenze</option>
<option value="Bologna">Bologna</option>
<option value="Agrigento">Agrigento </option>
<option value="Alessandria"> Alessandria</option>
<option value="Ancona">Ancona</option>
</select>
</td>
</tr>
<tr>
<td>Indirizzo</td>
<td><input type="text" name="indirizzo"></td>
</tr>
<tr>
<td>Telefono (senza spazi nè simboli)</td>
<td><input type="text" name="telefono"></td>
</tr>
<tr>
<td>Email</td>
<td><input name="email" type="text" maxlength="30"></td>
</tr>
<tr>
<td>Homepage</td>
<td><input type="text" name="homepage" value="http://"></td>
</tr>
<tr>
<td colspan="2">Firma</td>
</tr>
<tr>
<td colspan="2" align="center">
<textarea name="firma" rows="5" cols="32">Inserisci qui il tuo slogan!</textarea>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="button" value="Invia" onclick="Modulo()" >
</td>
</tr>
</form>
</table>
</body>
</html>
[/PHP]
E questa la pagina2.php che ho creato e che dovrebbe mandarmi tutto nella posta, anche se ....
Codice PHP:
<?php
// L'INDIRIZZO DEL DESTINATARIO DELLA MAIL
$to = "esempio@live.it";
// IL SOGGETTO DELLA MAIL
$subject = "Modulo proveniente dal sito [url]www.miosito.it[/url]";
// 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 .= "nickname: " . trim(stripslashes($_POST["Nickname"])) . "\n";
$body .= "password: " . trim(stripslashes($_POST["Password"])) . "\n";
$body .= "conferma: " . trim(stripslashes($_POST["Conferma"])) . "\n";
$body .= "nascita: " . trim(stripslashes($_POST["Nascita"])) . "\n";
$body .= "sesso: " . trim(stripslashes($_POST["Sesso"])) . "\n";
$body .= "citta: " . trim(stripslashes($_POST["Citta"])) . "\n";
$body .= "indirizzo: " . trim(stripslashes($_POST["Indirizzo"])) . "\n";
$body .= "telefono: " . trim(stripslashes($_POST["telefono"])) . "\n";
$body .= "email: " . trim(stripslashes($_POST["Email"])) . "\n";
$body .= "homepage: " . trim(stripslashes($_POST["Homepage"])) . "\n";
$body .= "firma: " . 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.";
}
?>
..... non ho compreso bene se in
Codice PHP:
$to = "esempio@live.it";
devo mettere il mio indirizzo di posta come o fatto, e poi in
Codice PHP:
// INTESTAZIONI SUPPLEMENTARI
$headers = "From: Modulo utenti<modulo@sito.it>";
cosa devo mettere, io l'ho lasciato cosi come l'ho trovato da dove ho mutuato questo codice.