欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

发送MIME邮件~~其实我对他的格式一窍不通,是看着OUTLOOK中的源码写的_PHP教程

程序员文章站 2022-05-31 19:01:32
...
class mime_mail { var $boundary0="----=_NextPart_000_00EE_01C07425.958FDFE0";//三条分界,0是附件,2是HTML,1是要附加的图片 var $boundary1="----=_NextPart_001_00EF_01C07425.958FDFE0"; var $boundary2="----=_NextPart_002_00F0_01C07425.958FDFE0"; var $body; function get_mail_header()//邮件头 { return $this->mail_header="MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="$this->boundary0" This is a multi-part message in MIME format. --$this->boundary0 Content-Type: multipart/related; boundary="$this->boundary1"; type="multipart/alternative" --$this->boundary1 Content-Type: multipart/alternative; boundary="$this->boundary2" "; } function str_row($str,$n)//把字符串分割成n行,OUTLOOK中好象必须把BASE64割成$n) { $new_str.=substr($str,$i,$n).chr(13).chr(10); $i+=$n; } else { $new_str.=$str; $i=strlen($str); } } return $new_str; } function loadfromfile($filename)//读出文件并编码 { $fp=fopen($filename,"rb"); $c=fread($fp,filesize($filename)); fclose($fp); return $this->str_row(base64_encode($c),77); } function file_header($filename)//给出文件头 { switch(substr($filename,strlen($filename)-3,3)) { case "gif": return "Content-Type: image/gif name="$filename""; break; case "jpg"; return "Content-Type: image/jpeg name="$filename""; break; case "txt"; return "Content-Type: text/plain name="$filename""; break; default: return "Content-Type: application/octetstream name="$filename""; } } function mail_body($str)//HTML部分 { $this->body.="--".$this->boundary2." Content-Type: text/html; charset="gb2312" ".$str." --".$this->boundary2."-- "; } function mail_picture($filename)//附件的图片,HTML中用到的这里必须添加,否则不能在本地显示 { if($filename==null) { $this->body.="--".$this->boundary1."-- "; } for($i=0;$ibody=str_replace($filename[$i],"cid:$cid",$this->body); $this->body.="--".$this->boundary1." "; $this->body.=$this->file_header($filename[$i])." Content-Transfer-Encoding: base64 "; $this->body.="Content-ID: "; $this->body.=$this->loadfromfile($filename[$i]); } $this->body.=" --".$this->boundary1."-- "; } function mail_attachment($filename)//附件 { for($i=0;$ibody.="--".$this->boundary0." "; $this->body.=$this->file_header($filename[$i])." Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="$filename[$i]" "; $this->body.=$this->loadfromfile($filename[$i]); } $this->body.="--".$this->boundary0."-- "; } function send_mail($to,$subject,$from)//发送 { mail($to,$subject,$this->body,"From:".$from." ".$this->get_mail_header()); } }; /*$s=new mime_mail; //这里是调用格式 $s->mail_body("heheehe发送MIME邮件~~其实我对他的格式一窍不通,是看着OUTLOOK中的源码写的_PHP教程发送MIME邮件~~其实我对他的格式一窍不通,是看着OUTLOOK中的源码写的_PHP教程"); $s->mail_picture(array("test.gif","Thumb1.jpg"));//如果没有就写mail_picture(null);下面也是 $s->mail_attachment(array("MIME_MAIL.PHP","Thumb1.jpg","newProject.rar","session.zip")); $s->send_mail("wan_dou@wenwenweb.com","测试","zhangxw@online.sh.cn");*/ ?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/531878.htmlTechArticlemail_header=MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=$this->boundary0 This is a multi-part message in MIME format. --$this->boundary0 Content-Type: multipart/relat...