Prova questo codice; dopo averlo salvato con Blocco Note come file UTF-8 puoi chiamarlo ad esempio "contact.php":
Codice PHP:
<?php
/* Change the email address to your own. $empty_fields_message and $thankyou_message can be changed if you wish. */
// Change to your own email address
$your_email = "TUO_INDIRIZZO_E-MAIL";
// This is what is displayed in the email subject line
// Change it if you want
$subject = "OGGETTO_E-MAIL_AUTOMATICO";
// This is displayed if all the fields are not filled in
$empty_fields_message = "<html><head><title>I n f o r m a t i o n</title><meta http-equiv='content-type' content='text/html; charset=utf-8'><meta http-equiv='Content-language' content='it'></head><body bgColor='#cceeff' scroll='auto'><br><br><p align='right'>Please go back and complete all the fields in the form. </p></body></html>";
// This is displayed when the email has been sent
$thankyou_message = "<html><head><title>I n f o r m a t i o n</title><meta http-equiv='content-type' content='text/html; charset=utf-8'><meta http-equiv='Content-language' content='it'>
<script type='text/javascript'><!--
var time = null
function move() {
window.location = 'http://it.altervista.org'
}
//--></script></head><body bgColor='#cceeff' onLoad=\"timer=setTimeout('move()',4000)\" scroll='auto'><br><br><p align='center'>Il tuo Messaggio è stato inviato al Sito Web.</p></body></html>";
// You do not need to edit below this line
$name = stripslashes($_POST['txtName']);
$email = stripslashes($_POST['txtEmail']);
$message = stripslashes($_POST['txtMessage']);
if (!isset($_POST['txtName'])) {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv='content-type' content='text/html; charset=utf-8'><meta http-equiv='Content-language' content='it'><title>:: Invia una eMail al sito Web :: </title><style type='text/css'>body { background-color:#ddd; text-align: center; }
.data { width:800px; height:34px; color:#000; background:#f0f0f0; text-align:center; border:2px dotted #b07; position:relative; margin:20px auto; padding:10px 0px 10px 0px; font-weight:normal; font-family:Tahoma; font-size:15px; }
.mess { width:800px; height:414px; color:#000; background:#e8e8e8; text-align:center; border:2px dotted #05c; position:relative; margin:20px auto; padding:10px 0px 10px 0px; font-weight:normal; font-family:tahoma; font-size:15px; }
textarea { width:700px; height:341px; overflow:auto; color:#000; background-color:#A8FF00; border:2px dotted #b07; position:relative; margin:0 auto; padding:10px 0 10px 17px; text-align:justify; text-indent:17pt; line-height:15pt; font-weight:normal; font-family:"Times New Roman"; font-size:19px; } </style> <body scroll='auto'>
<form method='post' action="<?php echo $_SERVER['REQUEST_URI']; ?>"><div class='data'><label for='txtName'>Il tuo Nome:</label>
<input onblur="this.style.backgroundColor='#A8FF00';this.style.color='#000'" onfocus="this.style.backgroundColor='#fff';this.style.color='#000'" style='width:220px; height:23px; padding:4px; color:#000; background-color:#A8FF00;' maxlength='70' type='text' title='Enter your name' name='txtName'>
<label for='txtEmail'>La tua E-mail:</label>
<input onblur="this.style.backgroundColor='#A8FF00';this.style.color='#000'" onfocus="this.style.backgroundColor='#fff';this.style.color='#000'" style='width:220px; height:23px; padding:4px; color:#000; background-color:#A8FF00;' maxlength='70' type='text' title='Enter your email address' name='txtEmail'>
<label title='Send your message'><input type='submit' value=' Invia '></label></div>
<div class='mess'><label for='txtMessage'>Il tuo Messaggio:</label><br><br>
<textarea onblur="this.style.backgroundColor='#A8FF00';this.style.color='#000'" onfocus="this.style.backgroundColor='#fff';this.style.color='#000'" title='Enter your message' name='txtMessage'></textarea></div></form></body></html>
<?php
} elseif (empty($name) || empty($email) || empty($message)) {
echo $empty_fields_message;}
else {
// Stop the form being used from an external URL
// Get the referring URL
$referer = $_SERVER['HTTP_REFERER'];
// Get the URL of this page
$this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];
// If the referring URL and the URL of this page don't match then
// display a message and don't send the email.
if ($referer != $this_url) {
echo "You do not have permission to use this script from another URL.";
exit; }
// The URLs matched so send the email
mail($your_email, $subject, $message, "From: $name <$email>");
// Display the thankyou message
echo $thankyou_message; }
?>
Per farlo funzionare, c'è da sostituire: 1.) Tuo_indirizzo_e-mail 2.) Oggetto_e-mail_automatico 3.) al posto di http://it.altervista.org scrivi URI della tua homePage.
Oltre a questo, puoi personalizzare i due messaggi ( di 'errore' / di 'messaggio inviato' ) e la grafica ( ad esempio: background- 'onfocus' / 'onblur' ), sostituendo ovunque trovi il colore A8FF00 con un altro colore, a tua scelta..