mail("$to","$subject","<font color=red>test</font>","From:$from \nContent-Type:text/html;charset=\"bg2312\"Content-Transfer-Encoding: base64");
解决方案 »
- realpath()疑问
- [function.file-put-contents]: failed to open stream: Permission denied in
- 请教系统时间差8小时的问题
- 中文字符、汉字在PHP正则表达式里该怎么表达?u4E00-\u9FA5、\x00-\xff、\0xB0-\0xFE、\x80-\xff、chr(0xa1) . "-" . chr(0xff)都不太正
- mysql中有没有类似php中的"list"函数?
- 谁有培PHP+MYSQL培训的资料,二个QQ相赠
- 文件管理(类资源管理器)
- Java 与 PHP 的MD5加密为什么不一样?
- 【在线等】这个地址如何在nginx里面配置?
- php mysql 请教如何获得同字段相同值合并为数组
- 举手之劳:只认字母和数字的正则表达式
- 紧急求救,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();
?>