当前位置: 首页 > 情感婚姻 > 文章

用MAIL函数发带附件的邮件的例子-PHP代码-PHP教程-幽默笑话

2019-07-11

用MAIL函数发带附件的邮件的例子-PHP代码-PHP教程-幽默笑话

文章内容用MAIL函数发带附件的邮件的例子修改时间:[2009/01/0709:02]阅读次数:[756]发表者:[起缘]classmime_mail{var$parts;var$to;var$from;var$headers;var$subject;var$body;/**voidmime_mail()*classconstructor*/functionmime_mail(){$this-parts=array();$this-to=;$this-from=;$this-subject=;$this-body=;$this-headers=;}/**voidadd_attachment(stringmessage,[stringname],[stringctype])*Addanattachmenttothemailobject*/functionadd_attachment($message,$name=,$ctype=application/octet-stream){$this-parts[]=array(ctype=$ctype,message=$message,encode=$encode,name=$name);}/**voidbuild_message(arraypart=*Buildmessagepartsofanmultipartmail*/functionbuild_message($part){$message=$part[message];$message=chunk_split(base64_encode($message));$encoding=base64;returnContent-Type:.$part[ctype].($part[name]name=.$part[name].:).nContent-Transfer-Encoding:$encodingnn$messagen;}/**voidbuild_multipart()*Buildamultipartmail*/functionbuild_multipart(){$boundary=(uniqid(time()));$multipart=Content-Type:multipart/mixed;boundary=$$boundary;for($i=sizeof($this-parts)-1;$i=0;$i--){$multipart.=n.$this-build_message($this-parts[$i]).--$boundary;}return$multipart.=--n;}/**voidsend()*Sendthemail(lastclass-functiontobecalled)*/functionsend(){$mime=;if(!empty($this-from))$mime.=From:.$;if(!empty($this-headers))$mime.=$;if(!empty($this-body))$this-add_attachment($this-body,,text/plain);$mime.=MIME-Version:$this-build_multipart();mail($this-to,$this-subject,,$mime);}};//endofclass/**Exampleusage*$attachment=fread(fopen(,r),filesize());$mail=newmime_mail();$mail-from=[emailprotected]$mail-headers=Errors-To:[emailprotected]$mail-to=[emailprotected]$mail-subject=Testing...$mail-body=Thisisjustatest.$mail-add_attachment($attachment,,image/jpeg);$mail-send();*/g。