2013-02-28 60 views
0

我遇到了下面的代码问题。我不知道什么可能是错误的,但我希望你能弄明白这一点或者我可以用附件发送电子邮件的简单方法......当我发送一条尝试消息时,它会在消息的头部发送类似这样的消息。 。带附件错误的PHP邮件

- 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>"; 
    } 
    } 

?> 

回答

0

只是用PHPMailer的,很简单,直接使用。