ah bene allora la parcella la invio a te
nome campo file = documento
Codice PHP:
<?php
$receiverMail = 'tuamail@mail.it';
$subject = 'CHECK LIST';
$nome = trim(stripslashes($_POST['nome']));
$cognome = trim(stripslashes($_POST['cognome']));
$struttura = trim(stripslashes($_POST['struttura']));
$auditor = trim(stripslashes($_POST['auditor']));
$verifica = trim(stripslashes($_POST['verifica']));
$checklist = trim(stripslashes($_POST['checklist']));
$d1_3= trim(stripslashes($_POST['d1_3']));
$d1_2= trim(stripslashes($_POST['d1_2']));
$d1_1= trim(stripslashes($_POST['d1_1']));
$d1_0= trim(stripslashes($_POST['d1_0']));
$d1_na= trim(stripslashes($_POST['d1_na']));
$d2_3= trim(stripslashes($_POST['d2_3']));
$d2_2= trim(stripslashes($_POST['d2_2']));
$d2_1= trim(stripslashes($_POST['d2_1']));
$d2_0= trim(stripslashes($_POST['d2_0']));
$d2_na= trim(stripslashes($_POST['d2_na']));
$d3_3= trim(stripslashes($_POST['d3_3']));
$d3_2= trim(stripslashes($_POST['d3_2']));
$d3_1= trim(stripslashes($_POST['d3_1']));
$d3_0= trim(stripslashes($_POST['d3_0']));
$d3_na= trim(stripslashes($_POST['d3_na']));
$d4_3= trim(stripslashes($_POST['d4_3']));
$d4_2= trim(stripslashes($_POST['d4_2']));
$d4_1= trim(stripslashes($_POST['d4_1']));
$d4_0= trim(stripslashes($_POST['d4_0']));
$d4_na= trim(stripslashes($_POST['d4_na']));
$d5_3= trim(stripslashes($_POST['d5_3']));
$d5_2= trim(stripslashes($_POST['d5_2']));
$d5_1= trim(stripslashes($_POST['d5_1']));
$d5_0= trim(stripslashes($_POST['d5_0']));
$d5_na=trim(stripslashes($_POST['d5_na']));
$email = $_POST['mail'];
$stringa1 = "ATTENZIONE Tutti i campi sono obbligatori!";
$stringa2 = "l'indirizzo mail non è valido";
$stringa3 = "la checklist è stata inviata.grazie!";
$msgformat = "La persona $nome $cognome ha compilato la seguente cechklist:\n\nnome checklist: $checklist\nstruttura: $struttura \nauditor: $auditor \nverifica del:$verifica \nmail: $email\nrisposte $d1_3 $d1_2 $d1_1 $d1_0 $d1_na \n$d2_3 $d2_2 $d2_1 $d2_0 $d2_na \n$d3_3 $d3_2 $d3_1 $d3_0 $d3_na \n$d4_3 $d4_2 $d4_1 $d4_0...";
$i=1;
while($i<=110){
if($_POST['note'.$i] != '')
$msgformat .= "Note".$i.":".$_POST['note'.$i]."";
$i++;
}
$allegato = $_FILES['documento']['tmp_name'];
$allegato_type = $_FILES['documento']['type'];
$allegato_name = $_FILES['documento']['name'];
$headers = "From: ".$email;
$msgformat_final = "";
// Verifico se il file è stato caricato correttamente via HTTP
// In caso affermativo proseguo nel lavoro...
if(is_uploaded_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}\"";
// Metto il separatore
$msgformat_final .= "--{$mime_boundary}\n";
// Questa è la parte "testuale" del messaggio
$msgformat_final .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$msgformat_final .= "Content-Transfer-Encoding: 7bit\n\n";
$msgformat_final .= $messaggio . "\n\n";
// Metto il separatore
$msgformat_final .= "--{$mime_boundary}\n";
// Aggiungo l'allegato al messaggio
$msgformat_final .= "Content-Disposition: attachment;\n";
$msgformat_final .= " filename=\"{$allegato_name}\"\n";
$msgformat_final .= "Content-Transfer-Encoding: base64\n\n";
$msgformat_final .= $data . "\n\n";
// chiudo con il separatore
$msgformat_final .= "--{$mime_boundary}--\n";
}else{
$msgformat_final = $msgformat;
}
if (( $nome == "" ) || ( $cognome == "" ) || ( $email == "" )){
echo "<script language=\"JavaScript\">\n";
echo "alert(\"$stringa1\");\n";
echo "java-script:history.go(-1);";
echo "</script>";
}elseif(preg_match("#([\w-\.]+)@((?:[\w]+\.)+)([a-zA-Z]{2,4})#", $email)){
mail($receiverMail, $subject, $msgformat_final, $headers);
echo "<script language=\"JavaScript\">\n";
echo "alert(\"$stringa3\");\n";
echo "java-script:history.go(-1);";
echo "</script>";
}
// OPZIONE2:
// popup di messaggio inviato e ridirezionamento ad una pagina web
// decommentare $redirect
// commentare tutto se si usa OPZIONE1 (per commentare usare /* all'inizio e */ alla fine delle righe da commentare)
/* echo "<script language=\"JavaScript\">\n";
echo "window.location.href=(\"$redirect\");\n";
echo "</script>";
}
*/
else{
echo "<script language=\"JavaScript\">\n";
echo "alert(\"$stringa2\");\n";
echo "java-script:history.go(-1);";
echo "</script>";
}
?>