0

我将两个脚本合并为一个脚本,所以它完成了需要做的事情。但它不是。不知何故,电子邮件附件部分无法正常工作,我尝试了许多更改,但无法正常工作。

问题

在邮箱中,收件人收到以下附件 (filename.pdf.pdf .dat),这应该是 filename.pdf

我在我正在使用的脚本和 html 表单下面添加了。在这两个页面中,我只会添加与附件有关的代码,以使问题更加清晰。

这是 send.php 的一部分:

    <form action="send_script.php" method="post" name="form1" id="form1" enctype="multipart/form-data">
    <div><input type="file" name="fileAttach" value="Zoeken"></div>
    <div><input type="submit" name="Submit" value="Verzenden"></div>
    </form>

这是 send_script.php 的一部分:

if($_FILES["fileAttach"]["name"] != "")
{
    $strFilesName = $_FILES["fileAttach"]["name"];
    $strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"]))); 
}

    ob_start(); //Turn on output buffering 
    --PHP-mixed-<?php echo $random_hash; ?>  
    Content-Type: application/octet-stream; name="<?php echo $strFilesName?>"  
    Content-Transfer-Encoding: base64  
    Content-Disposition: attachment; filename="<?php echo $strFilesName?>" 
    <?php echo $strContent; ?> 
    $message = ob_get_clean(); 
    $mail_sent = @mail( $to, $subject, $message, $headers ); 
    echo $mail_sent ? "Mail sent" : "Mail failed"; 
    ?>

编辑 1 上面的代码现在在下面的评论的帮助下被改变了感谢大家到目前为止帮助我。该文件现在正确地将 op 显示为 test.pdf 并且名称为 test。所以这是完美的。唯一的问题是它无法打开它给出以下错误。

错误 Adob​​e Acrobat:它作为电子邮件附件发送且未正确解码!

编辑 2 放弃上面的代码并开始更改以下内容,使其获得动态名称并适用于 pdf。

   $attachment = chunk_split(base64_encode(file_get_contents('attachment.zip')));

   --PHP-mixed-<?php echo $random_hash; ?>  
   Content-Type: application/zip; name="attachment.zip"  
   Content-Transfer-Encoding: base64  
   Content-Disposition: attachment  
   <?php echo $attachment; ?> 

到目前为止我改变了:

    $attachment = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"])));
    --PHP-mixed-<?php echo $random_hash; ?>  
    Content-Type: application/octet-stream; name="eenbestand.pdf"  
    Content-Transfer-Encoding: base64  
    Content-Disposition: attachment  
    <?php echo $attachment; ?> 

现在可以接收文件并正确打开,但现在是动态名称!

4

2 回答 2

0

你的Content-Type标题不应该是application/pdf吗?

(如果可以的话,我会将此作为评论添加,因为我不确定这是正确/相关的。)

于 2013-10-07T15:20:44.113 回答
-1

我通过简单地输入为我完成工作的正确代码来回答它。所有帮助过我的人都感谢。

    if($_FILES["fileAttach"]["name"] != "")
{
    $strFilesName = $_FILES["fileAttach"]["name"];
    $strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"]))); 
    $headers .= "--".$strSid."\n";
    $headers .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n"; 
    $headers .= "Content-Transfer-Encoding: base64\n";
    $headers .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
    $headers .= $strContent."\n\n";
}
于 2013-10-07T15:50:58.977 回答