特别容易的问题,发一封 HTML 格式的信 mail("$to","$subject","<font color=red>test</font>","From:$from \nContent-Type:text/html;charset=\"bg2312\"Content-Transfer-Encoding: base64"); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 mail("$to","$subject","<font color=red>test</font>","From:$from \nContent-Type:text/html;charset=\"GB2312\"Content-Transfer-Encoding: base64"); y10k's class:<?/*------------------------------------------------------------------------ 程序名称:Mime Sendmail pro Class 1.0 版权所有: y10k E-mail : [email protected] OICQ : 6795798 主页地址: http://www.zphp.com/------------------------------------------------------------------------*/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 = 'y') { 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; }}?>Example:------------------------------------------------------------------------------------You can send a non-HTML mail like this:<?$mail = new sendMailPro($to,$from,$subject,$body);$mail->send();?>You can send a HTML mail like this:<?$mail = new sendMailPro($to,$from,$subject,$body);$mail->isHtml();$mail->send();?>You can send a mail with Attachment like this:<?$mail = new sendMailPro($to,$from,$subject,$body);$mail->isHtml();$mail->addFile($attachmentpath);$mail->send();?> Something went wrong - -32300 : transport error - HTTP status code was not 200 请高手来看下 表单中复选框数据如何插入数据库? 在同一个表我想做一个下拉联动菜单? 一段代码求解 求救!帮帮小弟。。PHP Session问题???最好是有高手能在QQ上指点,万分感谢!如能见面定请吃饭。。。 紧急查询:分组,取各组最大! 请帮帮忙-变量问题 getallheaders函数问题 这是不是restful风格? 举手之劳:只认字母和数字的正则表达式 紧急求救,php显示图片的问题(在线等待 急急急急)
<?
/*------------------------------------------------------------------------
程序名称:Mime Sendmail pro Class 1.0
版权所有: y10k
E-mail : [email protected]
OICQ : 6795798
主页地址: http://www.zphp.com/
------------------------------------------------------------------------*/
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 = 'y') {
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;
}
}
?>Example:
------------------------------------------------------------------------------------
You can send a non-HTML mail like this:
<?
$mail = new sendMailPro($to,$from,$subject,$body);
$mail->send();
?>You can send a HTML mail like this:
<?
$mail = new sendMailPro($to,$from,$subject,$body);
$mail->isHtml();
$mail->send();
?>You can send a mail with Attachment like this:
<?
$mail = new sendMailPro($to,$from,$subject,$body);
$mail->isHtml();
$mail->addFile($attachmentpath);
$mail->send();
?>