title: PHP - trying to send email from script with attachment, but its not attachingHi
body: <p>I have a file that I am creating on the fly like this:</p>
  
  <pre><code>// Create and save the string on the file system
  $str = "Business Plan: \nSome more text";
  $fp = fopen("alex.txt", 'w+');
  fwrite($fp, $str);
  
  // email with the attachment
  $to = 'alex.genadinik@gmail.com'; 
  $subject = 'Your business plan attached';
  
  //create a boundary string. It must be unique 
  //so we use the MD5 algorithm to generate a random hash 
  $random_hash = md5(date('r', time())); 
  //define the headers we want passed. Note that they are separated with \r\n 
  $headers = "From: BusinessPlanApp@example.com"; 
  //add boundary string and mime type specification 
  $headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; 
  //read the atachment file contents into a string,
  //encode it with MIME base64,
  //and split it into smaller chunks
  $attachment = chunk_split(base64_encode(file_get_contents('alex.txt')));
  
  $contents = "some contents of the email";                   
  
  mail($to, $subject, $contents, $headers);
  </code></pre>
  
  <p>And the file is saving to the file system AND an email is getting sent to me with the right body and subject.</p>
  
  <p>The only thing going wrong is the attachment is unnamed file of zero bytes.  Any idea why that might happen? Is it a permissions issue? Or something in my email?</p>
  
  <p>Thanks!</p>