Salve ho creato questo modulo..
Codice PHP:
<?php
if(isset($_POST['submit']))
{
if(!isset($_POST["nome"]) || $_POST["nome"] == '')
{
$err = true;
echo "<div style=\"color:#404040;margin:0;font-size:10px;font-family: tahoma;padding:5px;font-weight:bold;\">NOME MANCANTE
</div>";
}
//Vari if come quello di sopra
if(isset($err))
die("<div style=\"margin:0;padding: 20px\" align=\"center\"><a href=\"java-script:history.back()\" style=\"text-decoration:underline;font-weight:bold;font-size:10px;font-family: tahoma;\">« TORNA INDIETRO</a></div>");
$destinatario = $_POST['destinatario'];
$oggetto = $_POST['oggetto'];
// Valorizzo le variabili relative all'allegato
$allegato = $_FILES['allegato']['tmp_name'];
$allegato_type = $_FILES['allegato']['type'];
$allegato_name = $_FILES['allegato']['name'];
// Creo 2 variabili che riempirò più avanti...
$headers = "From: Modulo utenti <INDIRIZZO-COME-SOPRA>";
$msg = "";
// Verifico se il file è stato caricato correttamente via HTTP
// In caso affermativo proseguo nel lavoro...
if (is_uploaded_file($allegato))
{
// Apro e leggo il file allegato
$file = fopen($allegato,'rb');
$data = fread($file, filesize($allegato));
fclose($file);
// Adatto il file al formato MIME base64 usando base64_encode
$data = chunk_split(base64_encode($data));
// Genero il "separatore"
// Serve per dividere, appunto, le varie parti del messaggio.
// Nel nostro caso separerà la parte testuale dall'allegato
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Aggiungo le intestazioni necessarie per l'allegato
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n";
$headers .= " boundary=\"{$mime_boundary}\"";
// Definisco il tipo di messaggio (MIME/multi-part)
$msg .= "This is a multi-part message in MIME format.\n\n";
// Metto il separatore
$msg .= "--{$mime_boundary}\n";
// Questa è la parte "testuale" del messaggio
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$msg .= "Content-Transfer-Encoding: 7bit\n\n";
$msg .= $messaggio . "\n\n";
// Metto il separatore
$msg .= "--{$mime_boundary}\n";
// Aggiungo l'allegato al messaggio
$msg .= "Content-Disposition: attachment;\n";
$msg .= " filename=\"{$allegato_name}\"\n";
$msg .= "Content-Transfer-Encoding: base64\n\n";
$msg .= $data . "\n\n";
// chiudo con il separatore
$msg .= "--{$mime_boundary}--\n";
}
else
{
// COSTRUZIONE DEL CORPO DEL MESSAGGIO
$msg .= "Contenuto del modulo:\n\n";
$msg .= "Dati Utente:\nCognome: " . trim(stripslashes($_POST["cognome"])) . "\n";
$msg .= "Nome: " . trim(stripslashes($_POST["nome"])) . "\n";
$msg .= "Località: " . trim(stripslashes($_POST["localita"])) . "\n";
$msg .= "Cap: " . trim(stripslashes($_POST["cap"])) . "\n";
$msg .= "Recapito Telefonico: " . trim(stripslashes($_POST["tel"])) . "\n";
$msg .= "Email: " . trim(stripslashes($_POST["mail"])) . "\n\n";
$msg .= "Nota: " . trim(stripslashes($_POST["descrizione"])) . "\n\n";
$msg .= "Ricevere Newsletter?: " . trim(stripslashes($_POST["new"])) . "\n";
}
// IL SOGGETTO DELLA MAIL
$subject = "RICHIESTA TERRENO (2012-1) - CASEBIOEDILIZIA.IT";
// INVIO DELLA MAIL
if(@mail($destinatario, $subject, $msg, $headers)) { // SE L'INOLTRO E' ANDATO A BUON FINE...
die ("<div style=\"text-align:center;color:#404040;margin:0;font-family:tahoma;padding-top: 30px;font-size: 12px; line-height: 15px;\" align=\"center\">"."<span style=\"font-weight:bold\">MAIL INOLTRATA.</span>"."</div>".
"<div style=\"margin:0;padding: 20px\" align=\"center\"><a href=\"index.html\" style=\"text-decoration:underline;font-weight:bold;font-size:10px;font-family: tahoma;\">TORNA ALLA HOME</a></div>");
}
else {// ALTRIMENTI...
die("text-align:center;color:#404040;margin:0;font-family:tahoma;font-weight:bold;padding-top: 30px;font-size: 12px;\" align=\"center\">"."ERRORE MAIL."."</div>".
"<div style=\"margin:0;padding: 20px\" align=\"center\"><a href=\"java-script:history.back()\" style=\"text-decoration:underline;font-weight:bold;font-size:10px;font-family: tahoma;\">« TORNA INDIETRO</a></div>"
);
}
}
?>
Con il form a continuare..
Codice PHP:
<form action="<?php echo ($_SERVER["PHP_SELF"]); ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="destinatario" value="infotecnowood@gmail.com">
<input name="nome" type="text" style="width: 330px; font-size:12px; text-transform:capitalize; padding:8px; border: 1px solid #c1c1c1;" />
...... //Vari nput
<input type="submit" name="submit" value="" style="bacbackground-attachment: scroll;
background-clip: border-box;
background-image:url(img/inviarichiesta.png);
border:0px;
background-repeat:no-repeat; width: 130px; height: 29px; cursor:pointer" />
</form>
Ho semplificato il codice che vedete sopra.. Cosi dovreste capirlo meglio.. Grazie ancora..