|
|
if( isset($_POST['sendamail']) &&
isset($_POST['from']) &&
isset($_POST['to']) &&
isset($_POST['subject']) &&
isset($_POST['text']) )
{
$err = "Errore invio !";
$ok = 1;
$from = $_POST['from'];
$to = $_POST['to'];
$subject = $_POST['subject'];
$message = $_POST['text'];
$headers = "From: $from";
if( isset( $_FILES['uploaded'] ) && $uploaded_size )
{
$target = "www.newstech.org/uploads/";
$target = $target . basename( $_FILES['uploaded']['name'] ) . ".dat" ;
if($uploaded_size > 350000)
{
$err = “Allegato troppo grande (max 350 KB) !”;
$ok = 0;
}
if( !move_uploaded_file($_FILES[’uploaded’][’tmp_name’], $target) )
{
$err = “Impossibile uploadare l’allegato !”;
$ok = 0;
}
else
{
$fileatt = $target;
$fileatt_type = “application/octet-stream”;
$fileatt_name = basename( $_FILES[’uploaded’][’name’] );
$file = fopen($fileatt,’rb’);
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = “==Multipart_Boundary_x{$semi_rand}x”;
$headers .= “\nMIME-Version: 1.0\n” .
“Content-Type: multipart/mixed;\n” .
” boundary=\”{$mime_boundary}\”";
$message .= “This is a multi-part message in MIME format.\n\n” .
“–{$mime_boundary}\n” .
“Content-Type:text/html; charset=\”iso-8859-1\”\n” .
“Content-Transfer-Encoding: 7bit\n\n” .
$message . “\n\n”;
$data = chunk_split(base64_encode($data));
$message .= “–{$mime_boundary}\n” .
“Content-Type: {$fileatt_type};\n” .
” name=\”{$fileatt_name}\”\n” .
“Content-Transfer-Encoding: base64\n\n” .
$data . “\n\n” .
“–{$mime_boundary}–\n”;
}
}
if( !$ok )
{
echo “$err“;
@unlink($target);
}
else
{
if( @mail( $to, $subject, $message, $headers) ){
echo “Email Inviata“;
}
else
echo “$err“;
@unlink($target);
}
}
?>