以下代码在Google Mail和Yahoo Mail中正常运行。附件文件名工作正常但在日文文件名的Hotmail附件中是乱码。
// multipart boundary
$message = "--{$mime_boundary}\n" . "Content-Type: ".$contentType."; charset=\"iso-8859-2,utf-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
//---- dummy size
$tempsize= 1024 ;
//---- dummy size
$ctrFileName = 0;
// preparing attachments
if(count($attachment) > 0){
foreach ($attachment as $file_data) {
$message .= "--{$mime_boundary}\n";
$data = chunk_split(base64_encode($file_data));
$message .= "Content-Type: application/octet-stream; name=\"".$filenameattach[$ctrFileName]."\"\n" .
"Content-Description: ".$filenameattach[$ctrFileName]."\n" .
"Content-Disposition: attachment;\n" . " filename=\"".$filenameattach[$ctrFileName]."\"; size=".$tempsize.";\n" .
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
$ctrFileName++;
//$message .= "--{$mime_boundary}--";
}
} else {
$message .= "--{$mime_boundary}--";
}
//$message .= "--{$mime_boundary}--";
//$returnpath = "-f" . $fromaddress;
$success = @mail($to, $subject, $message, $headers);