好的,php4 - 我明白了。也就是说,由于许多原因,无法升级到 php5 并使用 phpMailer - 就像我想的那样。我四处搜寻,没有其他答案。所以,这就是问题所在。我创建了一个文本文件 /tmp2/tmporder2
下面的代码可以很好地发送带有附件的电子邮件,但附件是 0 字节,NADA。
<?php
$path = '/tmp2';
$filename = 'tmporder2';
$mailto = 'dave@powerfulhosting.com';
$from_mail = 'estore order receipt';
$from_name = 'bagelworks order';
$replyto = '';
$subject = 'TESTING EMAIL ATTACHMENT';
$file = $path.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$message=$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!";
}
?>
任何想法,将不胜感激。