title: PHP Email headers? Mime mistakes or something else...help to understand?
body: <p>I'm a junior in php. Now I trying to send some attachments throught php mail(), But when I'm going to read the mail, it displays (see down here) only in the text form. Also the attachments content is blank. I use an mail form found on internet. I think the error is with the /r/n or /n and things like that. Sorry for bed english. I can explain more if asked, await for your help! Sorry for too much code posting but i think it's neccesary to understand...</p>
  
  <p><strong>THE FORM</strong></p>
  
  <pre><code>&lt;form action="mailme.php"  method="post" enctype="multipart/form-data"&gt;
  -+-+-  other inputs and select -+-+-
  
  &lt;input name="upload[]" type="file"&gt;
  &lt;input name="upload[]" type="file"&gt;
  
  ...other file attachments like that above
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>Retrive variables and then 
  $headers ="From: ".$SenderName." &lt;".$from."&gt;\n";
  
  // boundary 
      $semi_rand = md5(time()); 
      $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
  
  // headers for attachment 
      $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" .   "
                   boundary=\"{$mime_boundary}\""; 
  
  // multipart 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"; 
      $message .= "--{$mime_boundary}\n";
  
  // preparing attachments
      for($x=0;$x&lt;count($files);$x++){
              $file = fopen($files[$x],"rb");
              $data = fread($file,filesize($files[$x]));
              fclose($file);
              $data = chunk_split(base64_encode($data));
              $message .= "Content-Type: {\"application/octet-stream\"};\n" .  
  
                          " name=\"$files[$x]\"\n" . 
              "Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" . 
              "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
              $message .= "--{$mime_boundary}\n";
      }
  
      // send
  
      $success = @mail($to, $subject, $message, $headers); 
      if ($success) { 
              echo "&lt;p&gt;mail sent to $to!&lt;/p&gt;"; 
      } else { 
              print_r($files);
  echo "&lt;p&gt;mail could not be sent!&lt;/p&gt;".$from.'&lt;br&gt;'.$message.'&lt;br&gt;'.$to.'&lt;br&gt;'.$subject.'&lt;br&gt;'.$SenderName; 
      } 
  </code></pre>
  
  <p><strong>THE OUTPUT</strong></p>
  
  <pre><code>MIME-Version: 1.0
  Content-Type: multipart/mixed;
  
  boundary="==Multipart_Boundary_x553132b5cf2c4c84ecdbd3285b8b590dx"
  
  This is a multi-part message in MIME format.
  
  --==Multipart_Boundary_x553132b5cf2c4c84ecdbd3285b8b590dx
  Content-Type: text/html; charset="iso-8859-1"
  Content-Transfer-Encoding: 7bit
  
  Message &lt;b&gt;with&lt;b&gt; some &lt;a href="html"&gt;html&lt;/a&gt;!
  
  --==Multipart_Boundary_x9351bff6284cb1fc967281cfede5762cx
  Content-Type: {"application/octet-stream"};
  name=""
  Content-Disposition: attachment;
  filename=""
  Content-Transfer-Encoding: base64
  
  .....BLANK CONTENT! LIKE NO IMAGE WAS ATTACHED......    
  
  
  --==Multipart_Boundary_x553132b5cf2c4c84ecdbd3285b8b590dx
  </code></pre>