PHP邮件附件错误

时间:2013-02-28 01:50:37

标签: php function email email-attachments

我遇到了以下代码的问题。我不知道可能出现了什么问题,但我希望你能够解决这个问题或者我可以通过附件发送电子邮件的简单方法...当我发送一条试信时,它会在邮件的标题中发送这样的内容。

- 244f3f04128cb4e6797d0019662a1aaa Content-Type:application / octet-stream; name =“phpStorm.txt”Content-Transfer-Encoding:base64 Content-Disposition:attachment;文件名= “phpStorm.txt” QW1iZXIgVG93bnNlbmQNCg0KNTQzMDQ1LTE4MDIyMDEzDQowMDAwMXh3Smg1blJxU0hVTEVkVFpR TmZIRWF6SXUNCmc2bTRnTE1QOTZOMlFPVnpWckphZ0Y1cmpzZm9zTQ0KMmk0ZkFDQnVZV2MzMDlO cCFXb05kRW1EcnpWcVBi

以下代码:

<?php

    //file attachment
    $strSid = md5(uniqid(time()));
    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  .= "Content-Type: multipart/mixed; ";
    $headers .= $strContent."\n\n";

    if(mail($to, $subject, $message, $headers)){
    echo "<div class=\"message_success\">Your message has successfully been       sent</div>";//echo 'Your message has successfully been sent';
    } else {
    echo "<div class=\"message_error\">Message failed to sent, try again</div>";
    }
    }

?>

1 个答案:

答案 0 :(得分:0)

只需使用PHPMailer,即可轻松直接使用。