PHP mail() attachment wasn't correctly decoded
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/1438594/php-mail-attachment-is-corrupt">PHP mail() attachment is corrupt</a>  </p>
</blockquote>



<p>I am trying to send email with attachment using PHP mail() function. Email goes through properly and attachment is also received. But when  I try to open attachment, a message is displayed saying file wasn't correctly  decoded. </p>

<p>I have copied my code below. Please help me to find bug in my code. </p>

<pre><code> $recieverAdd ='abc@gmail.com';
$subject ='Email with attachment';
$filename ='abc.pdf';
$file = '/home/abc/abc.pdf';
$file_size = filesize($file);
$handle = fopen($file, "rb");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$uid = md5(uniqid(time()));
$name = basename($file);
$from_name = 'ABC';
$from_mail = 'admin@gmail.net';
$header = "From: $from_name";       
$header .= "\nMIME-Version: 1.0\n" . 
        "Content-Type: multipart/mixed;\n" . 
        " boundary=\"{$uid}\"";

$message="&lt;p&gt;&lt;b&gt;Hello&lt;/p&gt;";
$messageBody =  "--{$uid}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; 


$messageBody .= "--{$uid}\n". "Content-Type: application/octet-stream; \n ".
                "name=\"{$filename}\" ".
            "Content-Description: {$filename} " .
            "Content-Disposition: attachment ".
            "filename=\"{$filename2}\"; size={$file_size}; " .
            "Content-Transfer-Encoding: base64\n\n". $content."\n\n".         "--{$uid}--\n";       
if(mail($recieverAdd,$subject,$messageBody,$header))
 return true;
 else 
 return false;
</code></pre>
