Php邮件附件错误



我的代码出了什么问题?邮件发送很好,文本也很好,但附件显示为noname.txt请帮助。

$upload_name=$_FILES["resume"]["name"];
$upload_type=$_FILES["resume"]["type"];
$upload_size=$_FILES["resume"]["size"];
$upload_temp=$_FILES["resume"]["tmp_name"];
$file = $upload_temp;
$content = chunk_split(base64_encode(file_get_contents($file)));
$num = md5(uniqid(time()));
$email_to = "noname@example.com";
$email_subject = $name . " Applied for a job in website careers page";
$email_message = "<b>Form details below.</b><br />";
$email_message .= "<tr><td><strong>Last Name</strong> </td><td>".$name."     </td></tr>";
$email_message .= "<tr><td><strong>Phone</strong> </td><td>".$phone." </td></tr>";
$headers .='Reply-To: '. $email_to . "rn" ;
$headers .= "MIME-Version: 1.0rn";
$headers .= "Content-Type: multipart/mixed;  boundary="".$num.""rnrn";
$headers .= "This is a multi-part message in MIME format.rn";
$headers .= "--".$num."rn";
$headers .= "Content-Type: text/html; charset=iso-8859-1rn";
$headers .= "Content-Transfer-Encoding: 8bitrnrn";
$headers .= $email_message."rnrn";
$headers .= "--".$num."n";
$headers .= "Content-Type:".$upload_type.";  name="".$upload_name.""rnrn";
 $headers .= "Content-Transfer-Encoding: base64rn";
 $headers .= "Content-Disposition: attachment; filename="".$upload_name.""rnrn";
 $headers .= $content."rnrn";
 $headers .= "--".$num."--"; 
 if(@mail($email_to, $email_subject, "", $headers)){
        echo "Mail Send";
 }
else  {
       echo "Mail not sent.";
}

请帮忙。提前谢谢。

试试这个。。。

我已经添加了在邮件中发送的附加文件的示例代码

<?php
function mail_attachment($filename, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
    $file = $path.$filename;
    $file_size = filesize($file);
    $handle = fopen($file, "r");
    $content = fread($handle, $file_size);
    fclose($handle);
    $content = chunk_split(base64_encode($content));
    $uid = md5(uniqid(time()));
    $name = basename($file);
    $header = "From: ".$from_name." <".$from_mail.">rn";
    $header .= "Reply-To: ".$replyto."rn";
    $header .= "MIME-Version: 1.0rn";
    $header .= "Content-Type: multipart/mixed; boundary="".$uid.""rnrn";
    $header .= "This is a multi-part message in MIME format.rn";
    $header .= "--".$uid."rn";
    $header .= "Content-type:text/plain; charset=iso-8859-1rn";
    $header .= "Content-Transfer-Encoding: 7bitrnrn";
    $header .= $message."rnrn";
    $header .= "--".$uid."rn";
    $header .= "Content-Type: application/octet-stream; name="".$filename.""rn"; // use different content types here
    $header .= "Content-Transfer-Encoding: base64rn";
    $header .= "Content-Disposition: attachment; filename="".$filename.""rnrn";
    $header .= $content."rnrn";
    $header .= "--".$uid."--";
    if (mail($mailto, $subject, "", $header)) {
        echo "mail send ... OK"; // or use booleans here
    } else {
        echo "mail send ... ERROR!";
    }
}
?>

如果您发送zip文件,请尝试使用以下

<?php    $my_file = "filename.zip";
    $my_path = $_SERVER['DOCUMENT_ROOT']."/path/";
    $my_name = "resr";
    $my_mail = "test@resr.com";
    $my_replyto = "test@test.com";
    $my_subject = "This is a mail with attachment.";
    $my_message = "Hallo,rndo you like this script? I hope it will help.rnrngr. Olaf";
    mail_attachment($my_file, $my_path, "recipient@mail.org", $my_mail, $my_name, $my_replyto, $my_subject, $my_message);
?>

相关内容

  • 没有找到相关文章

最新更新