关于用php发送有附件的邮件,附件无法打开(急!!! 在线等) 把其他代码贴出来Look Look! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 其他就是email的内容而已。$message定义的是一个html的邮件,我就是想再同时发送一个到两个pdf文件,文件的位置是在网上的,我是在$attachment里给出的,能够认到差不多的大小,应该是找到这个文件了。再来就是发送,用的是 mail ($email, $subject, $message, $headers);请各位帮忙了。 http://www.yesky.com/SoftChannel/72342371945349120/20020510/1610577.shtmlhttp://geo.jlu.edu.cn/date/mypost/show.php?id=32是偶参考的教程,在网上其他地方找到的也是差不多的。 邮件的格式不对,你用foxmail打开一个邮件,看看他的源码.你的邮件的“\r\n”加的不全,head和body间的就不全。 我没有foxmail,我都是用ultraedit打开的。看不到\r\n,除了foxmail还有其他方法看到\r\n吗?之前我也有考虑过这个问题,并在每行后面都加上\r\n,有时候反而让pdf不按照附件方式显示了。请问是在每一行后面都加吗?还有分号是不是每行都要加? $headers = "MIME-Version: 1.0\r\n";$headers .= "From: XXX<[email protected]>\r\n";$headers .= "Content-type: multipart/mixed; boundary=\"4094d055be8ab\"\r\n\r\n"; $message = "--4094d055be8abContent-type: text/html;Content-transfer-encoding: 8bit;$message--4094d055be8abContent-Type: application/pdf; name=\"1.pdf\"Content-Transfer-Encoding: base64Content-Disposition: attachment; filename=\"1.pdf\" $read--4094d055be8ab--"; 谢谢,不过好像还是老问题。hahawen帮偶改的是不是:1。boundary=\"4094d055be8ab\"\r\n\r\n"; 加上\r\n\r\n以后无变化。如果和上一句前换行的话,就无法正确显示html格式的邮件和pdf附件。全部都是code。2。另外$message前换了行,也没有帮助。 下面是唠叨老大的一个发附件的脚本.<?php/*$to 目标$subject 主题$message 正文$from 发自$content_type 类型$attache 附件,文件名放在数组中*/$email = $_POST['email'];$email = trim("$email");$message = "hello";function mail2( $to, $subject, $message, $from, $content_type, $attache="") { if(!empty($from)) $head = "From: $from\n"; if(empty($content_type)) $content_type = "text/plain"; if(is_array($attache)) { $boundary = "===" . md5(uniqid("")) . "==="; $head .= "Mime-Version: 1.0\nContent-Type: multipart/mixed; boundary=\""; $head .= "$boundary\"\n\nThis is a multi-part message in MIME format.\n\n"; $head .= "--$boundary\n"; $head .= "Content-Type: $content_type\n"; $head .= "\n$message\n\n"; while(list($key, $val) = each($attache)) { $fd = fopen("$val", "r") or die("unable to open file $val"); $contents = chunk_split(base64_encode(fread($fd,filesize("$val")))); fclose($fd); $head .= "--$boundary\n"; $head .= "Content-Type: application/octet-stream; name=\"".basename($val); $head .= "\"\nContent-Transfer-Encoding: BASE64\n"; $head .= "Content-Disposition: attachment; filename=\"".basename($val); $head .= "\"\n\n" . $contents . "\n\n"; } $head .= "--" . $boundary . "--\n\n"; }else{ if(!empty($content_type)) { $head .= "Content-Type: $content_type\n"; $head .= "\n$message\n"; } } return mail($to,$subject,"",$head ); } mail2("$email","",$message,"","",array("a.doc"));?> 紧急求助关于php读取c#保存到oracle数据库图片的问题 紧急求救,关于php连接db2的操作 多关键词模糊搜索 关于国外主机申请的疑问 PHP优先级【逻辑或】 “||” 左右两边的优先级是否一样 PHP 新手:推荐关于PHP的网站,中文英文都可以,来者有分 有谁知道? 关于广告轮播的问题? 谁有类似QQ的PHP代码? PHP继承的问题,调用父类的方法this指向问题 大家看看这个网站值几钱? *.htc这是什么文件?
请各位帮忙了。
http://geo.jlu.edu.cn/date/mypost/show.php?id=32是偶参考的教程,在网上其他地方找到的也是差不多的。
之前我也有考虑过这个问题,并在每行后面都加上\r\n,有时候反而让pdf不按照附件方式显示了。
请问是在每一行后面都加吗?还有分号是不是每行都要加?
$headers .= "From: XXX<[email protected]>\r\n";
$headers .= "Content-type: multipart/mixed; boundary=\"4094d055be8ab\"\r\n\r\n"; $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--";
1。
boundary=\"4094d055be8ab\"\r\n\r\n";
加上\r\n\r\n以后无变化。
如果和上一句前换行的话,就无法正确显示html格式的邮件和pdf附件。全部都是code。
2。
另外$message前换了行,也没有帮助。
/*
$to 目标
$subject 主题
$message 正文
$from 发自
$content_type 类型
$attache 附件,文件名放在数组中
*/
$email = $_POST['email'];
$email = trim("$email");$message = "hello";function mail2( $to, $subject, $message, $from, $content_type, $attache="") {
if(!empty($from)) $head = "From: $from\n";
if(empty($content_type)) $content_type = "text/plain"; if(is_array($attache)) {
$boundary = "===" . md5(uniqid("")) . "===";
$head .= "Mime-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"";
$head .= "$boundary\"\n\nThis is a multi-part message in MIME format.\n\n";
$head .= "--$boundary\n";
$head .= "Content-Type: $content_type\n";
$head .= "\n$message\n\n"; while(list($key, $val) = each($attache)) {
$fd = fopen("$val", "r") or die("unable to open file $val");
$contents = chunk_split(base64_encode(fread($fd,filesize("$val"))));
fclose($fd);
$head .= "--$boundary\n";
$head .= "Content-Type: application/octet-stream; name=\"".basename($val);
$head .= "\"\nContent-Transfer-Encoding: BASE64\n";
$head .= "Content-Disposition: attachment; filename=\"".basename($val);
$head .= "\"\n\n" . $contents . "\n\n";
}
$head .= "--" . $boundary . "--\n\n";
}else{
if(!empty($content_type)) {
$head .= "Content-Type: $content_type\n";
$head .= "\n$message\n";
}
}
return mail($to,$subject,"",$head );
} mail2("$email","",$message,"","",array("a.doc"));?>