ecco il codice:
codice HTML:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Language" content="it">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>CONTATTI</title>
</head>
<body>
<form action="elabora.php" method="post" id="modulo">
<table>
<tr>
<td>Il Suo indirizzo e-mail*</td>
<td><label>
<input name="mail" type="text" id="mail" />
</label></td>
</tr>
<tr>
<td>Oggetto*</td>
<td><label>
<input name="object" type="text" id="object" />
</label></td>
</tr>
<tr>
<td>Messaggio*</td>
<td>
<textarea name="body" cols="30" rows="5" id="body"></textarea>
</td>
</tr>
<tr>
<td><label></label>
</td>
<td><label>
<input type="submit" name="submit" id="submit" value="Invia" /> <input type="reset" name="cancella" id="cancella" value="Ripristina" />
</label></td>
</tr>
</table>
</form>
</body>
</html>
e poi il file elabora.php
Codice PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<title>Pagina php per l'elaborazione di un form e l'invio di mail lato server</title>
<link rel="stylesheet" href="stili.css" type="text/css">
</head>
<body>
<?php
// indirizzo di chi riceve la mail è sottolineato ma nel codice non sottilineatelo
if ((trim($_POST['object']) != "") && (trim($_POST['body']) != "")) { //questo fa si che se i campi "oggetto" e "messaggio" sono vuoti la form non invia nessuna mail
$to = "mirkocoppola80@gmail.com";
$headers = "From: " . $_POST['mail'] . "\n";
// soggetto della mail
$subject = "Modulo proveniente da www.tuosito.it";
// corpo messaggio
$body = "Contenuto del modulo:\n\n";
$body .= "Inviata da: " . trim(stripslashes($_POST["mail"])) . "\n"; //indirizzo e-mail che manda la mail, come si vede riprende l'id del campo destinato all'inserimento della mail del mittente
$body .= "Oggetto: " . trim(stripslashes($_POST["object"])) . "\n"; //oggetto del messaggio
$body .= "testo: " . trim(stripslashes($_POST["body"])) . "\n"; //messaggio
// invio mail
mail($to, $subject, $body, $headers); // SE L'INOLTRO E' ANDATO A BUON FINE...
echo "La mail è stata inviata con successo. Grazie per averci contattato";
} else {// altrimenti
echo "Deve compilare la form prima di inviare.";
}
?>
</body>
</html>