title: mail headers shown in mail body, no file, no html
body: <p>I'm having trouble with my emails with attached file.
  The headers, including html(parsed as text) and file (also parsed as text), which are all in the headers, appear as the message body. this code used to work, but I can't figure what changed.</p>
  
  <p>There is a random factor, some times the mail do arrive correctly, but I can't seem to figure out the pattern (assuming there is) that will ruin the mail/make it work.</p>
  
  <p>this is my code to generate the mail:</p>
  
  <pre><code>$file = $path.$filename;
  $file_size = filesize($file);
  $handle = fopen($file, "r");
  $content = fread($handle, $file_size);
  fclose($handle);
  $content = chunk_split(base64_encode($content));
  $uid = md5(uniqid(time()));
  $name = basename($file);
  $header .= "MIME-Version: 1.0\r\n";
  $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
  $header .= "This is a multi-part message in MIME format.\r\n";
  $header .= "--".$uid."\r\n";
  $header .= "Content-Type: text/html; charset=utf-8\r\n";
  $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
  $header .= $message."\r\n\r\n";
  $header .= "--".$uid."\r\n";
  $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; 
  // use different content types here
  $header .= "Content-Transfer-Encoding: base64\r\n";
  $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
  $header .= $content."\r\n\r\n";
  $header .= "--".$uid."--";
  $mailto = 'yanivshimony@gmail.com';
  if (mail($mailto, $subject, "", $header)) {
  
      echo "1"; // or use booleans here
  } else {
      echo "mail send ... ERROR!";
  }
  </code></pre>
  
  <p>I tried removing all the headers, and was left only with the following headers making it work:</p>
  
  <pre><code>$header .= "Content-Type: text/html; charset=utf-8\r\n";
  $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
  $header .= $message."\r\n\r\n";
  </code></pre>
  
  <p>so its quite usless, as its just a normal html email, with no multipart/attachment/anything - but the HTML is parsed :)</p>
  
  <p>Any idea what could break the headers??
  Thanks!</p>