PHP邮件附件显示noname.txt

时间:2015-03-03 02:39:50

标签: php email

我的代码有什么问题? 邮件发送罚款和文本也很好,但附件显示像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 . "\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.";
                            }

请帮忙。提前谢谢。

1 个答案:

答案 0 :(得分:0)

您考虑过使用PHPMailer吗?根据我的经验,可以避免许多这些麻烦。

否则,请尝试更改:

$headers .= "Content-Type:".$upload_type.";name=\"".$upload_name."\"\r\n\r\n";

要:

$headers .= "Content-Type: multipart/mixed; name=\"".$upload_name."\"\r\n\r\n";