内容传输编码:7位

时间:2013-01-22 16:00:24

标签: php character-encoding

我这里有问题。我创建了一个mail()PHP脚本来发送附件,您通常会发送到您的常规电子邮件提供商。问题是我只能发送一定数量的字符。例如,我可以发送一个名为“新文本文档”的文件,但如果我尝试发送一个名为“Microsoft Word(3)的新文档”的文件,它就永远不会收到我的电子邮件。

有人可以告诉我为什么会这样吗?

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 = &$_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();*/
}  
}
?

<!doctype html>
<html>
<head>
  <title>A contact form</title>
</head>
<body>
  <?php
   if(isset($_GET['sent']) === true){
    echo '<p>Thanks for contacting us</p>';
   } else {
    if(empty($errors) === false){
         echo '<ul>';
         foreach($errors as $error){
          echo '<li>', $error ,'</li>';
         }
         echo '</ul>';
    }
            ?>
            <form action="" method="post" enctype="multipart/form-data">
                    <p>
                            <label for="name">Name:</label><br />
                            <input type="text" name="name" id="name" <?php     if(isset($_POST['name']) === true){ echo 'value="', strip_tags($_POST['name']), '"';} ?>>
                    </p>
                    <p>
<label for="email">Email:</label><br />
                            <input type="text" name="email" id="email" <?php     if(isset($_POST['email']) === true){ echo 'value="', strip_tags($_POST['email']), '"';} ?>>
                    </p>
                    <p>
                            <label for="message">Message:</label><br />
                            <textarea name="message" id="message"><?php     if(isset($_POST['message']) === true){ echo strip_tags($_POST['message']); } ?></textarea>
                    </p>
                    <p>
                            List of files allowed: .pdf, .odt, .doc(x), xls(x), ppt(x), >xps, xml
                    </p>
                    <p>
                            <input type="file" name="filename">
                    </p>
                    <p>
                            <input type="submit" value="submit">
                    </p>
            <?php
                    }
            ?>
            </form>
</body>
</html>

它发送附件但仅当文件具有例如文件名称为10个字符时,但如果文件具有15个字符则不发送

0 个答案:

没有答案