title: PHP send mail error when receiving attachments - octet-stream; name=""
body: <p>I have a problem regarding PHP send mail. I am trying to send an attachment with the help of PHP from an online form. The data in the email I received is perfectly fine but the attachment sometimes comes like : </p>
  
  <pre><code>2 application octet-stream; name="" 
  </code></pre>
  
  <p>(this would be a plain text as an attachment with this name). What am I doing wrong?</p>
  
  <pre><code>    &lt;?php 
  // if button is pressed - ACTION
  if (isset($_POST['reg_application'])) {
  
  // get fields into variables
  $firstname = strip_tags($_POST['firstname']);;
  $lastname = strip_tags($_POST['lastname']);
  $email = strip_tags($_POST['email']);
  $phone = strip_tags($_POST['phone']);
  
  // get other form fields into variables
  $country = strip_tags($_POST['country']);
  $experience = strip_tags($_POST['experience']);
  $englishlevel = strip_tags($_POST['englishlevel']);
  $availability = strip_tags($_POST['availability']);
  $licence = strip_tags($_POST['drivingLicence']);
  $nursing = strip_tags($_POST['nursing']);
  $signed = "Signed";
  
  
  
      //Deal with the email
      $to = 'example@example.com';
      $subject = "+1 $country - $firstname $lastname";
  
      //Deal with sending
          //$message = strip_tags($_POST['message']);
          $message = "ALL DETAILS\n\nFirst Name: $firstname\nLast Name: $lastname\nEmail: $email\nPhone: $phone\nCountry: $country\nExperience: $experience\nEnglish: $englishlevel\nAvailability: $availability\nDriving Licence: $licence\nNursing Experience: $nursing\nAccepted T&amp;C: $signed";
          $attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name'])));
          $filename = $_FILES['file']['name'];
  
          $boundary =md5(date('r', time())); 
  
          $headers = "From: example@example.com\r\nReply-To: daniel@hidd.co.uk";
          $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\"";
  
          $message="This is a multi-part message in MIME format.
  
  --_1_$boundary
  Content-Type: multipart/alternative; boundary=\"_2_$boundary\"
  
  --_2_$boundary
  Content-Type: text/plain; charset=\"iso-8859-1\"
  Content-Transfer-Encoding: 7bit
  
  $message
  
  --_2_$boundary--
  --_1_$boundary
  Content-Type: application/octet-stream; name=\"$filename\" 
  Content-Transfer-Encoding: base64 
  Content-Disposition: attachment 
  
  $attachment
  --_1_$boundary--";
  
          mail($to, $subject, $message, $headers);
          header("Location: success.php?application-sent");
  
  }
  
  
   ?&gt;
  </code></pre>