程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 發送MIME郵件~~其實我對他的格式一竅不通,是看著OUTLOOK中的源碼寫的

發送MIME郵件~~其實我對他的格式一竅不通,是看著OUTLOOK中的源碼寫的

編輯:關於PHP編程

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割成<77字符/行才行 { $i=0; if($n<1)return $str; while($i$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: <$cid> "; $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"); $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("[email protected]","測試","[email protected]");*/ ?>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved