2015-03-03 113 views
0

我的代碼有什麼問題?郵件發送罰款和文字也很好,但附件顯示像noname.txt請幫助。Php郵件附件錯誤

$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 = "[email protected]"; 
$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 . "\r\n" ; 
$headers .= "MIME-Version: 1.0\r\n"; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$num."\"\r\n\r\n"; 
$headers .= "This is a multi-part message in MIME format.\r\n"; 
$headers .= "--".$num."\r\n"; 
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n"; 
$headers .= "Content-Transfer-Encoding: 8bit\r\n\r\n"; 
$headers .= $email_message."\r\n\r\n"; 
$headers .= "--".$num."\n"; 
$headers .= "Content-Type:".$upload_type."; name=\"".$upload_name."\"\r\n\r\n"; 
$headers .= "Content-Transfer-Encoding: base64\r\n"; 
$headers .= "Content-Disposition: attachment; filename=\"".$upload_name."\"\r\n\r\n"; 
$headers .= $content."\r\n\r\n"; 
$headers .= "--".$num."--"; 

if(@mail($email_to, $email_subject, "", $headers)){ 
     echo "Mail Send"; 
} 
else { 
     echo "Mail not sent."; 
} 

請幫忙。提前致謝。

+0

'Content-Disposition'頭部放在'$ headers。= $ email_message之前。「\ r \ n \ r \ n」;'線路問題消失了嗎? – 2015-03-03 04:43:22

+0

不..還是一樣 – user2459458 2015-03-03 05:44:33

回答

0

嘗試......

我有添加示例代碼附加文件中的郵箱發送

<?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.">\r\n"; 
    $header .= "Reply-To: ".$replyto."\r\n"; 
    $header .= "MIME-Version: 1.0\r\n"; 
    $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n"; 
    $header .= "This is a multi-part message in MIME format.\r\n"; 
    $header .= "--".$uid."\r\n"; 
    $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; 
    $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; 
    $header .= $message."\r\n\r\n"; 
    $header .= "--".$uid."\r\n"; 
    $header .= "Content-Type: application/octet-stream; name=\"".$filename."\"\r\n"; // use different content types here 
    $header .= "Content-Transfer-Encoding: base64\r\n"; 
    $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n"; 
    $header .= $content."\r\n\r\n"; 
    $header .= "--".$uid."--"; 
    if (mail($mailto, $subject, "", $header)) { 
     echo "mail send ... OK"; // or use booleans here 
    } else { 
     echo "mail send ... ERROR!"; 
    } 
} 
?> 

如果您發送的壓縮文件試試如果你將使用以下

<?php $my_file = "filename.zip"; 
    $my_path = $_SERVER['DOCUMENT_ROOT']."/path/"; 
    $my_name = "resr"; 
    $my_mail = "[email protected]"; 
    $my_replyto = "[email protected]"; 
    $my_subject = "This is a mail with attachment."; 
    $my_message = "Hallo,\r\ndo you like this script? I hope it will help.\r\n\r\ngr. Olaf"; 
    mail_attachment($my_file, $my_path, "[email protected]", $my_mail, $my_name, $my_replyto, $my_subject, $my_message); 
?> 
+0

你的代碼和我的代碼有什麼區別? – user2459458 2015-03-03 05:46:05

+0

我的代碼適合我 – 2015-03-03 05:46:59

+0

你有什麼錯誤? – 2015-03-03 05:47:13