关于用php发送有附件的邮件,附件无法打开(急!!! 在线等)
cccca 2004-05-03 07:11:08 这段code是我参考网上的写的,关于php发送email的教学好像都差不多,类似的问题也看到人家问过,不过没有解答。 或者就是两大段class, 看的不是很明白。
最好是希望可以在这个code的基础上稍作改动。
ps: 我也参考过自己outlook收发有附件的email的code,好像在$header,$message上没有很大问题,所以我个人意见是不是$read出错? 不过这个几乎就是照网上抄的。
$attachment = "...path for....1.pdf";
$fp = fopen($attachment, "r");
$read = fread($fp, filesize($attachment));
$read = base64_encode($read);
$read = chunk_split($read);
//fclose($fp); 这句是否必要??
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: XXX<XXX@XXX.XX>\r\n";
$headers .= "Content-type: multipart/mixed; boundary=\"4094d055be8ab\"";
$message = "--4094d055be8ab
Content-type: text/html;
Content-transfer-encoding: 8bit;
$message
--4094d055be8ab
Content-Type: application/pdf;
name=\"1.pdf\"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=\"1.pdf\"
$read
--4094d055be8ab--";
收到的email有附件,大小也对,就是无法打开。
出错信息:could not open, because it is either not a supported file type or because the file has been corrupted (for example, it was sent as an email attachment and wasn't correctly decoded)
试过jpg的,也是无法打开。文件大小差不多。
请各位高手帮忙,先谢了。