Ciao,
io non sono un grandissimo esperto, ma per il mio sito ho fatto così:
Ho fatto la pagina contatti che va rinominata .php [la mia si chiama proprio contatti.php]
ed ho inserito questo codice
Codice PHP:
<html xmlns="http://www.w3.org/1999/xhtml" lang="it">
<head>
....
....
<title>Contatti</title>
....
....
</head>
<body>
<div>
<?php echo stripslashes($_GET[message])?>
<form method="post" action="amailzing.php" enctype="multipart/form-data">
Inserisci il tuo nome
<input type="text" name="nameREQUIRED" />
Inserisci il tuo indirizzo Email
<input type="text" name="emailREQUIRED" />
Inserisci il messaggio
<textarea name="message" cols="30" rows="7"> </textarea>
<input type="submit" value="Send the email!" />
</div></body>
nella stessa cartella dove ho salvato la pagina contatti.php va salvato un altro file:
apri il block notes e gli copi tutto questo codice
Codice PHP:
<?php
// aMAILzing version 1.1 - [url]http://scripts.inexistent.org[/url]
// Copyright ©2005, 2007, Christine R., [email]cineee@gmail.com[/email]
// Last updated December 2nd, 2007.
// Please don't redistribute without written permission. :)
// To change the settings, simply change "email@email.com" to the email address
// you wish for the emails to be sent to, and "Thanks for your email,
// I'll get back on you later!" to the confirmation message you want to be shown
// when everything is working just fine and the message was sent! :)
// Please avoid use of quoation signs. (")
$myemail = "gookart21@yahoo.it";
$thankyou = "Grazie per averci scritto, sarete ricontattati il prima possibile :)";
// If you're using file uploads, you may want to specify allowed file extensions.
// To allow all extensions, simply remove the line below. (or put "//" in front of it)
$allowed_fileuploads = "png gif jpg zip rar html";
// If you find yourself receiving a lot of spam, something as easy as asking an addition question
// may decrease the amount noticeably, if not get rid of the spam entirely. To utilize this
// simple way of doing it, add an extra input to your form, in which you promt the visitor to
// enter the sum of 5 and 6. Give the input the name of "math". Then uncomment (remove //'s)
// the following three lines.
// if($_POST['math'] != '11' && $_POST['math'] != 'eleven'){
// die("Come on, that's kindergarten-level math. ;) Try again! What's the answer to 5+6?");
// }
// Don't edit anything below this line, unless you know what you are doing! :)
// Make sure nobody gets stuck in infinite loops.
if(!$_POST)
die('Please don\'t access this file directly.');
// Gather all the required fields. Remove the REQUIRED part from their names.
// The bug which made the required fields appear last in the email has been fixed.
while(list($key,$val) = each($_POST)) {
if(stristr($key,'REQUIRED')){
$key = str_replace('REQUIRED','',$key);
$fields[$key] = $val;
if($val == ''){
$missing[] = '[b]'.$key.'[/b]';
}
} else {
$fields[$key] = $val;
}
}
// If there is a myemail value in the form, send the email to it instead!
if(isset($fields['myemail']))
$myemail = $fields['myemail'];
// Set default values if there exists none.
if(isset($fields['name'])){ $name = $fields['name']; } else { $name = "aMAILzing"; }
if(isset($fields['email'])){ $email = $fields['email']; } else { $email = $myemail; }
if(isset($fields['subject'])){ $subject = $fields['subject']; } else { $subject = "mail dal sito"; }// Validate inputs for email injections.
reset($_POST);
$injection = false;
foreach($_POST as $key => $value){
if(preg_match("/(content-type|bcc:|cc:|script|onclick|onmouseover)/i", $value)){
$injection = true;
}
}
// Write the start of the email body.
$message = "The following form was sent to you from your website!\n";
$message .= "-----------------------------------------------------------\n";
$message .= "Ip: ".$_SERVER['REMOTE_ADDR']."\n";
$message .= "Host: ".@gethostbyaddr($_SERVER['REMOTE_ADDR'])."\n";
$message .= "Browser: ".$_SERVER['HTTP_USER_AGENT']."\n";
$message .= "Referrer: ".$_SERVER['HTTP_REFERER']."\n\n";
// Find all the fields, and add them to the email.
foreach($fields as $k=>$v) {
if($v && !stristr($k,'REQUIRED'))
if(is_array($v))
$message .= ucfirst($k).": ".implode(', ', $v)."\n\n";
else
$message .= ucfirst($k).": $v\n\n";
}
// Write the rest of the email body.
$message .= "-----------------------------------------------------------\n";
$message .= " ";
$message = stripslashes($message);
// Write the headers.
$mail_boundary = "x".md5(time())."x";
$header = "From: $name <$email>\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-type: multipart/mixed; boundary=\"{$mail_boundary}\"\n";
$header .= "X-Priority: 3\n";
$header .= "X-MSMail-Priority: Normal\n";
$header .= "X-Mailer: aMAILzing 1.1 [url]http://scripts.inexistent.org\n[/url]";
$header .= "This is a multi-part message in MIME format.\n\n";
$header .= "--{$mail_boundary}\n";
$header .= "Content-type: text/plain; charset=\"iso-8859-1\"\n";
$header .= "Date: ".date('R')."\n";
$header .= "Content-Transfer-Encoding:7bit\n\n";
$header .= $message."\n\n";
// Attach the uploaded files, if there is any.
if($_FILES){
if (get_magic_quotes_runtime() == 1){
set_magic_quotes_runtime(0);
}
foreach($_FILES as $key=>$value){
foreach($value as $key2 => $value2){
$$key2 = $value2;
}
if (is_uploaded_file($tmp_name)) {
if(isset($allowed_fileuploads)){
$fileextensions = explode(' ', $allowed_fileuploads);
$thisfile = explode('.', $name);
$thisfile = array_pop($thisfile);
if(!in_array($thisfile, $fileextensions)){
die("The type of file is not allowed as attachments. Please go back and upload another file.");
}
}
$fp = fopen($tmp_name,'rb');
$read = fread($fp,$size);
fclose($fp);
$file = base64_encode($read);
$file = chunk_split($file);
$header .= "--$mail_boundary\n";
$header .= "Content-type: $type; name=\"$name\"\n";
$header .= "Content-Transfer-Encoding:base64\n";
$header .= "Content-Disposition: attachment; filename=\"$name\"\n\n";
$header .= $file."\n\n";
}
}
}
// Now, lets deal with what we've got so far!
$valid_email = eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email);
if(!isset($missing) && $valid_email && $injection != true) {
mail($myemail,$subject,'',$header);
} elseif(!$valid_email){
$thankyou = "L'idirizzo mail inserito non è valido";
} elseif($injection == true){
die("Email injection attempt detected and blocked.");
} else {
if(count($missing)>1){
$last = array_pop($missing);
$themissing = implode(', ',$missing).' and '.$last;
$plu = 's';
} else {
$themissing = $missing[0];
}
$thankyou = "Ci dispiace, ma non hai compilato il campo$plu ".$themissing.". Perfavore compila tutti i campi.";
}
// And, in the very end, we've got to catch the referrers and redirect back to where we came from.
$ref = getenv("HTTP_REFERER");
if (stristr($ref,'?'))
$sep = "&";
else
$sep = "?";
$thankyou .= ' [size="1"].[/size]';
$thankyou = urlencode($thankyou);
header("Location: $ref${sep}message=$thankyou");
// If you want a separate thankyou page, change the above to
// header("Location: filename.html");
// or
// header("Location: filename.html?message=$thankyou");
// And then, we're done!
?>
il file lo salvi con nome amailzing.php
ed in quel codice devi solo mettere il tuo indirizzo mail in questa riga:
(") $myemail = "tuo indirizzo mail";
p.s. ovviamente il sito deve fornire servizi php