title: Unable to attach pdf to email in php
body: <p>I've tried to follow the examples given in this forum, like the example given by freestate <a href="https://stackoverflow.com/questions/30887610/error-with-php-mail-multiple-or-malformed-newlines-found-in-additional-header">here - Error with PHP mail(): </a>.</p>
  
  <p>Below is my code copied from his revised example.  It emails fine.  And an attachment is shown in the email when received. However it cannot be opened and is always 125k in size.</p>
  
  <p>I have verified that a file size is returned with "$file_size = filesize($file);".  Also that the "fopen" does open the stream.  In fact before I added the Multipart to the header, I could see the content in the body of the text (albeit not readable).</p>
  
  <p>I'm only trying to attach a basic pdf file, on a window's platform (windows 10),  Apache 2.4, PHP 5.6.16.0.</p>
  
  <p>What would cause the attachment to fail to attach properly?</p>
  
  <pre><code>    emailer('//serverName/path/', 'documentName.pdf');
  
      function eMailer($path, $filename)
      {
          $eol = PHP_EOL;
          $to = "xxxx@yyyyyyyy.com";
          $subject = "File Name: ".$filename;
  
          $body = "The this the written content of the body";
  
          $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()));
  
          $header = "From: NameOfPerson &lt;their@emailAddress.com&gt;".$eol.
                "MIME-Version: 1.0\r\n".
                "Content-Type: multipart/mixed; boundary=\"".$uid."\"";
  
          $message = "--".$uid.$eol.
               "Content-Type: text/html; charset=ISO-8859-1".$eol.
               "Content-Transfer-Encoding: 8bit".$eol.$eol.
               $body.$eol.
  
               "--".$uid.$eol.
               "Content-Type: application/pdf; name=\"".$filename."\"".$eol.
               "Content-Transfer-Encoding: base64".$eol.
               "Content-Disposition: attachment; filename=\"".$filename."\"".$eol.
               $content.$eol.
               "--".$uid."--";
  
          echo (mail($to, $subject, $message, $header))?'success':'failure';  
      }
  </code></pre>