title: Content-Transfer-Encoding: 7bit
body: <p>I have a problem here. I created a mail() PHP script to send attachments and you would normally send in your regular email provider. The problem is that I can only send files up to a certain number of characters. For example I can send a file with this name "New Text Document" but if I try to send a file with this name "New Document of Microsoft Word (3)" it never gets to my email.</p>
  
  <p>Can someone please tell me why this happens?</p>
  
  <pre><code>error_reporting(-1);
  if(empty($_POST) === false){
  $errors = array();
  
  $name = $_POST['name'];
  $email = $_POST['email'];
  $file = $_FILES['filename'];
  
  if(empty($name) === true || empty($email) === true || empty($_POST['message']) === true){
    $errors[] = 'Name, email and message are required!';
  } else {
    if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){
     $errors[] ='Not a valid email';
    }
    if(ctype_alpha($name) === false){
     $errors[] ='Name must only contain letters';
    }
  }
  $message;
  if(empty($errors) === true){
    if($_FILES['filename']['error'] == UPLOAD_ERR_OK){
     $boundary = '-----' . md5(rand()) . '---';
     $headers = array(
      'MIME-Version: 1.0',
      "Content-type: multipart/mixed; boundary=\"{$boundary}\"",
      "From: {$email}"
     );
     $message = array(
      "--{$boundary}",
      'Content-type: text/html',
      'Content-Transfer-Encoding: 7bit',
      '',
      chunk_split($_POST['message']),
      "--{$boundary}",
      "Content-type: {$file['type']}; name=\"{$file['name']}\"",
      "Content-Disposition: attachment; filename=\"{$file['name']}\"",
      'Content-Transfer-Encoding: base64',
      '',
      chunk_split(base64_encode(file_get_contents($file['tmp_name']))),
      "--{$boundary}--"
     );
     $message = implode("\r\n", $message);
    } else {
     $headers = array(
      "From: {$email}"
     );
     $message = &amp;$_POST['message'];
    }
    //send email
    var_dump(mail($email, 'Contact form', $message, implode("\r\n", $headers)));
  
     echo $_FILES['filename']['name'];
    /*//redirect user
    header('Location: index.php?sent');
    exit();*/
  }  
  }
  ?
  
  &lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;A contact form&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;?php
     if(isset($_GET['sent']) === true){
      echo '&lt;p&gt;Thanks for contacting us&lt;/p&gt;';
     } else {
      if(empty($errors) === false){
           echo '&lt;ul&gt;';
           foreach($errors as $error){
            echo '&lt;li&gt;', $error ,'&lt;/li&gt;';
           }
           echo '&lt;/ul&gt;';
      }
              ?&gt;
              &lt;form action="" method="post" enctype="multipart/form-data"&gt;
                      &lt;p&gt;
                              &lt;label for="name"&gt;Name:&lt;/label&gt;&lt;br /&gt;
                              &lt;input type="text" name="name" id="name" &lt;?php     if(isset($_POST['name']) === true){ echo 'value="', strip_tags($_POST['name']), '"';} ?&gt;&gt;
                      &lt;/p&gt;
                      &lt;p&gt;
  &lt;label for="email"&gt;Email:&lt;/label&gt;&lt;br /&gt;
                              &lt;input type="text" name="email" id="email" &lt;?php     if(isset($_POST['email']) === true){ echo 'value="', strip_tags($_POST['email']), '"';} ?&gt;&gt;
                      &lt;/p&gt;
                      &lt;p&gt;
                              &lt;label for="message"&gt;Message:&lt;/label&gt;&lt;br /&gt;
                              &lt;textarea name="message" id="message"&gt;&lt;?php     if(isset($_POST['message']) === true){ echo strip_tags($_POST['message']); } ?&gt;&lt;/textarea&gt;
                      &lt;/p&gt;
                      &lt;p&gt;
                              List of files allowed: .pdf, .odt, .doc(x), xls(x), ppt(x), &gt;xps, xml
                      &lt;/p&gt;
                      &lt;p&gt;
                              &lt;input type="file" name="filename"&gt;
                      &lt;/p&gt;
                      &lt;p&gt;
                              &lt;input type="submit" value="submit"&gt;
                      &lt;/p&gt;
              &lt;?php
                      }
              ?&gt;
              &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>It sends attachments but only if the file has for example the file has a name 10 characters, but if it has 15 it won't send</p>