<?php
$to = "QUA METTO EMAIL";
$mail = $_POST['mail'];
$oggetto = $_POST['oggetto'];
$testomessaggio = $_POST['testomessaggio'];
$attachment = $_FILES['attachment']['tmp_name'];
$attachment_type = $_FILES['attachment']['type'];
$attachment_name = $_FILES['attachment']['name'];
$headers = "From: " . $to;
if (is_uploaded_file($attachment))
{
$file = fopen($attachment,'rb');
$data = fread($file, filesize($attachment));
fclose($file);
$data = chunk_split(base64_encode($data));
$func_rand = md5(time());
$mime_boundary = "==Multipart_divisor_x{$func_rand}x";
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n";
$headers .= " divisor=\"{$mime_boundary}\"";
$body .= "This is a multi-part message in MIME format.\n\n";
$body .= "--{$mime_boundary}\n";
$body .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$body .= "Content-Transfer-Encoding: 7bit\n\n";
$body .= "From :" . $mail . "\n\n";
$body .= $messaggio . "\n\n";
$body .= "--{$mime_boundary}\n";
$body .= "Content-Disposition: attachment;\n";
$body .= " filename=\"{$attachment_name}\"\n";
$body .= "Content-Transfer-Encoding: base64\n\n";
$body .= $data . "\n\n";
$body .= "--{$mime_boundary}--\n";
}
else
{
$body = $testomessaggio;
}
if (mail($to, $oggetto, $body, $headers))
{
echo "<em>Mail e allegato inviati correttamenti</em>";
}else{
echo "<em>Ci sono problemi, verifica il codice php</em>";
}
?>