Corrupted Attachments ???
I spent many hours with corrupted attachments (of all types of files) - The answer: a blank line is needed after $msg.=$file \r\n \r\n [incredible but true].
Heres some useful code for sending an attachment, and display html OR text depending on the users email-reader.
i work with many different systems, so...
<?php if (strtoupper(substr(PHP_OS,0,3)=='WIN')) {
  $eol="\r\n";
} elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) {
  $eol="\r"; 
} else {
  $eol="\n"; 
} ?>
<?php
$f_name="../../letters/".$letter;    $handle=fopen($f_name, 'rb');
$f_contents=fread($handle, filesize($f_name));
$f_contents=chunk_split(base64_encode($f_contents));    $f_type=filetype($f_name);
fclose($handle);
$emailaddress="user@example.com";
$emailsubject="Heres An Email with a PDF".date("Y/m/d H:i:s");
ob_start();
  require("emailbody.php");     $body=ob_get_contents(); ob_end_clean();
$headers .= 'From: Jonny <jon@example.com>'.$eol;
$headers .= 'Reply-To: Jonny <jon@example.com>'.$eol; 
$headers .= 'Return-Path: Jonny <jon@example.com>'.$eol;     $headers .= "Message-ID:<".$now." TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol;           $mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol; 
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol; 
$msg = "";
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: application/pdf; name=\"".$letter."\"".$eol;   $msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Disposition: attachment; filename=\"".$letter."\"".$eol.$eol; $msg .= $f_contents.$eol.$eol;
$msg .= "Content-Type: multipart/alternative".$eol; 
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= "This is a multi-part message in MIME format.".$eol;
$msg .= "If you are reading this, please update your email-reading-software.".$eol;
$msg .= "+ + Text Only Email from Genius Jon + +".$eol.$eol;
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $body.$eol.$eol;
$msg .= "--".$mime_boundary."--".$eol.$eol;   ini_set(sendmail_from,'from@example.com');  mail($emailaddress, $emailsubject, $msg, $headers); 
ini_restore(sendmail_from);
?>
I hope this helps.
Jon Webb [Madrid&London]
[EDITOR thiago NOTE: Code has a fix from o.straesser AT gmx DOT de]