<?php
if(isset($_POST['email']) && isset($_POST['nome'])){
$header="";
$msg="";
$boundary='--' . md5( uniqid("boundary") );
$ctencoding="8bit";
$subject="Invio allegato";
$body=$_POST['testo'];
$to="lukino.188@gmail.com";
$from=$_POST['email'];
$ctype="application/x-unknown-content-type";
$basename=$_FILES['all']['tmp_name'];
$name=$_FILES['all']['name'];
$header.="From: $from\nX-Priority: 3\nTo: $to\n";
$header.="Mime-Version: 1.0\nContent-Type: multipart/mixed;\n boundary=\"$boundary\"\n";
$header.="Content-Transfer-Encoding: 8bit\n";
$msg .="This is a multi-part message in MIME format.\n--$boundary\n";
$msg .= "Content-Type: text/plain; charset=iso-8859-9\n";
$msg .= "Content-Transfer-Encoding: 8bit\n\n" . $body ."\n";
$msg .="--$boundary\nContent-type: $ctype;\n name=\"$name\"\n";
$msg .="Content-Transfer-Encoding: base64\nContent-Disposition: attachment\n filename=\"$name\"\n";
$linesz= filesize( $basename)+1;
$fp= fopen( $basename, 'r' );
$content = chunk_split(base64_encode(fread( $fp, $linesz)));
fclose($fp);
$msg .= chr(13) . chr(10).$content;
$result = @mail($to,$subject,$msg."\n",$header);
if($result){
echo "<p>Il tuo messaggio è stato inoltrato con successo!</p><p>Grazie!</p>";
}else{
echo "<p>E' stato riscontrato un errore sul server.<br>Impossibile inviare il messaggio.</p><p>Riprova più tardi.</p>";
}
}else{
echo "<p>Non hai compilato tutti i campi del modulo!</p><p>Campi mancanti:</p>";
if(!isset($_POST['nome'])){ echo "Nome<br>";}
if(!isset($_POST['email'])){ echo "Indirizzo e-mail<br>";}
}
?>