我使用PHP mail()
功能與附件使用Content-Type: multipart/mixed
頭,但它始終返回noname.txtPHP的mail()帶附件的回報noname.txt
這裏是我的代碼:
$upload_name=$_FILES["upload"]["name"];
$upload_type=$_FILES["upload"]["type"];
$upload_size=$_FILES["upload"]["size"];
$upload_temp=$_FILES["upload"]["tmp_name"];
$subject = "Subject";
$to="[email protected]";
$message="message";
$fp = fopen($upload_temp, "rb");
$file = fread($fp, $upload_size);
$file = chunk_split(base64_encode($file));
$num = md5(time());
//Normal headers
$headers = "From: Info Mail<[email protected]>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; ";
$headers .= "boundary=".$num."\r\n";
$headers .= "--$num\r\n";
// This two steps to help avoid spam
$headers .= "Message-ID: <".gettimeofday()." [email protected]".$_SERVER['SERVER_NAME'].">\r\n";
$headers .= "X-Mailer: PHP v".phpversion()."\r\n";
// With message
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$message."\n";
$headers .= "--".$num."\n";
// Attachment headers
$headers .= "Content-Type:".$upload_type." ";
$headers .= "name=\"".$upload_name."\"r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; ";
$headers .= "filename=\"".$upload_name."\"\r\n\n";
$headers .= "".$file."\r\n";
$headers .= "--".$num."--";
// SEND MAIL
[email protected]($to, $subject, $message, $headers);
fclose($fp);
In Mail收件箱它返回:
在此先感謝...
我想你是在你的MIME類型的文件,你要在這一行上傳文件的問題$ headers。=「Content-Type:multipart/mixed;」; – Ricky 2014-10-07 11:32:07
@Ricky然後,我可以用什麼來代替_Content-Type:multipart/mixed_? – edCoder 2014-10-07 11:37:13
我建議使用像SwiftMailer這樣的電子郵件庫。然後發送帶有附件和不同編碼的電子郵件真的很容易。 – TiMESPLiNTER 2014-10-07 11:46:58