如何发送HTML文件的邮件! 你的这个HTML的邮件要在哪个地方发送?比喻说,在电子邮件客户端发送,还是在免费油箱中发送? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你个class<?Class sendMailPro { var $to = array(); // ÊÕÐÅÈË var $from = ""; // ·¢ÐÅÈË var $headers = ""; // Í·ÐÅÏ¢ var $subject = ""; // Ö÷Ìâ var $body = ""; // ÄÚÈÝ var $mime = ""; // MimeÐÅÏ¢ var $parts = array(); // ¸½¼þ var $filec; // ÎļþÊýÄ¿ var $boundary = ""; // ·Ö¸ô·û var $type = "text/plain"; function sendMailPro($to, $from = "", $subject = "",$body = "", $headers = "") { if(is_array($to)) { $this->to = $to; } else { $this->to[0] = $to; } $this->from = $from; $this->subject = $subject; $this->body = $body; $this->headers = $headers; $this->boundary = Chop("b".md5(uniqid(time()))); } function addreciever($to) { $this->to[] = $to; return 1; } function addAttachment($filecontent, $filename = "", $filetype = "application/octet-stream") { $this->filec++; if($filename=="") { $filename = "attachment_".$this->filec; } $this->parts[] = array( "type" => $filetype, "content" => $filecontent, "name" => $filename ); return 1; } function addFile($filename) { $filecontent = fread(fopen($filename,"r"), filesize($filename)); $filetype = "application/octet-stream"; $this->addAttachment($filecontent, $filename, $filetype); } function buildBody() { $body =$this->body; $boundary = $this->boundary; $bodyr = "--".$boundary; $bodyr = "\nContent-Type: ".$this->type."; charset=\"GB2312\"\nContent-Transfer-Encoding: quoted-printable\n\n"; $bodyr.= $body."\n\n"; $bodyr.= "--".$boundary; return $bodyr; } function buildContent($part) { $content = $part["content"]; // $content = chunk_split(base64_encode($content)); $encoding = "base64"; $return = "Content-Type: ".$part["type"].";"; $return .= " name = \"".$part["name"]."\"\n"; $return .= "Content-Transfer-Encoding: $encoding\n"; $return .= "Content-Disposition: attachment; filename=\"".$part["name"]."\"\n\n"; $return .= "$content\n"; return $return; } function buildMail() { $boundary = $this->boundary; $multipart = "Content-Type: multipart/mixed; boundary = \"$boundary\"\n\nThis is a MIME encoded message send by sendMailPro class(zlib).\n\n--$boundary"; $multipart.= $this->buildBody(); $attachmentCount = count($this->parts); if($attachmentCount==0) { return $multipart; } for($i = $attachmentCount-1;$i>=0;$i--){ $multipart .= "\n".$this->buildContent($this->parts[$i])."--$boundary"; } $multipart = chop($multipart); $multipart.= "--\n"; return $multipart; } function isHtml($html = 'yes') { if($html) { $this->type = "text/html"; } return 1; } function send() { if($this->from<>'') { $this->mime.= "From: ".$this->from."\n"; } $this->mime.= "MIME-Version: 1.0\n"; $this->mime.= $this->buildMail(); $to_count = count($this->to); for($i = 0;$i<$to_count;$i++) { mail($this->to[$i], $this->subject, "", $this->mime); } return 1; } function attachmentCount() { return $this->filec; } } ?> 中文注释没有了,或者你来信要。[email protected] 在mail函数的第四个参数中添加这个Content-Type: text/html; charset="GB2312" php获取mysql中文后显示乱码,能帮修改一下吗 如何读取文件? PHP从文件最后读取文本文件 我有一些php题目,大家来做啊,谁还有更多的题目? 关于$_POST和BBS程序中格式化输入的问题(老鸟菜鸟都请进) 一个理解不透的问题(用php实现从局域网到internet) 如何在javascript中嵌入php语句? 关于位置定位的问题 请问新闻分类显示怎么分? 不同页面,php如何js传值? 羽凡请进啊!!! 关于计数器的问题!
Class sendMailPro {
var $to = array(); // ÊÕÐÅÈË
var $from = ""; // ·¢ÐÅÈË
var $headers = ""; // Í·ÐÅÏ¢
var $subject = ""; // Ö÷Ìâ
var $body = ""; // ÄÚÈÝ
var $mime = ""; // MimeÐÅÏ¢
var $parts = array(); // ¸½¼þ
var $filec; // ÎļþÊýÄ¿
var $boundary = ""; // ·Ö¸ô·û
var $type = "text/plain";
function sendMailPro($to, $from = "", $subject = "",$body = "", $headers = "") {
if(is_array($to)) {
$this->to = $to;
} else {
$this->to[0] = $to;
}
$this->from = $from;
$this->subject = $subject;
$this->body = $body;
$this->headers = $headers; $this->boundary = Chop("b".md5(uniqid(time())));
}
function addreciever($to) {
$this->to[] = $to;
return 1;
}
function addAttachment($filecontent, $filename = "", $filetype = "application/octet-stream") {
$this->filec++;
if($filename=="") {
$filename = "attachment_".$this->filec;
}
$this->parts[] = array(
"type" => $filetype,
"content" => $filecontent,
"name" => $filename
);
return 1;
}
function addFile($filename) {
$filecontent = fread(fopen($filename,"r"), filesize($filename));
$filetype = "application/octet-stream";
$this->addAttachment($filecontent, $filename, $filetype);
}
function buildBody() {
$body =$this->body;
$boundary = $this->boundary;
$bodyr = "--".$boundary;
$bodyr = "\nContent-Type: ".$this->type."; charset=\"GB2312\"\nContent-Transfer-Encoding: quoted-printable\n\n";
$bodyr.= $body."\n\n";
$bodyr.= "--".$boundary;
return $bodyr;
}
function buildContent($part) {
$content = $part["content"];
// $content = chunk_split(base64_encode($content));
$encoding = "base64";
$return = "Content-Type: ".$part["type"].";";
$return .= " name = \"".$part["name"]."\"\n";
$return .= "Content-Transfer-Encoding: $encoding\n";
$return .= "Content-Disposition: attachment; filename=\"".$part["name"]."\"\n\n";
$return .= "$content\n";
return $return;
}
function buildMail() {
$boundary = $this->boundary;
$multipart = "Content-Type: multipart/mixed; boundary = \"$boundary\"\n\nThis is a MIME encoded message send by sendMailPro class(zlib).\n\n--$boundary";
$multipart.= $this->buildBody();
$attachmentCount = count($this->parts);
if($attachmentCount==0) {
return $multipart;
}
for($i = $attachmentCount-1;$i>=0;$i--){
$multipart .= "\n".$this->buildContent($this->parts[$i])."--$boundary";
}
$multipart = chop($multipart);
$multipart.= "--\n";
return $multipart;
}
function isHtml($html = 'yes') {
if($html) {
$this->type = "text/html";
}
return 1;
}
function send() {
if($this->from<>'') {
$this->mime.= "From: ".$this->from."\n";
}
$this->mime.= "MIME-Version: 1.0\n";
$this->mime.= $this->buildMail();
$to_count = count($this->to);
for($i = 0;$i<$to_count;$i++) {
mail($this->to[$i], $this->subject, "", $this->mime);
}
return 1;
}
function attachmentCount() {
return $this->filec;
}
}
?>
Content-Type: text/html; charset="GB2312"