请问怎么用mail()发送多个附件? 这个可不是一句话,就能讲完的,总之首先创建一个分割符,用来区分文本,以及附件,然后就是发送了,具体的楼主可以到网上查一查smtp协议,或者找一个支持多个附件的php smtp信件发送类看看 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <?/* Mailer** author: episome <webmaster(at)3ants.org>** website: http://3ants.org**/class mailer{ var $mail = array(); function mailer(){ $this->mail['boundary'] = '===' . md5(uniqid('')) . '==='; $this->mail['content_type'] = 'text/plain'; $this->mail['attaches'] = ''; $this->mail['sender'] = 'none'; $this->mail['from'] = '[email protected]'; } function addAttaches($attaches,$attacheContent=null){ if(is_null($attacheContent)){ if(is_string($attaches)){ $attaches = explode(',',$attaches); } foreach ($attaches as $attache){ if(!is_file($attache)){ continue; } $attacheContent = join('',file($attache)); $this->_addAttacheContent($attache,$attacheContent); } }else{ $this->_addAttacheContent($attaches,$attacheContent); } } function _addAttacheContent($attache,$attacheContent){ $this->mail['attaches'] .= "--" . $this->mail['boundary'] . "\n"; $this->mail['attaches'] .= "Content-Type: application/octet-stream; name=\"" . basename($attache) . "\"\nContent-Transfer-Encoding: BASE64\nContent-Disposition: attachment; filename=\"" . basename($attache) . "\"\n"; $this->mail['attaches'] .= "\n" . chunk_split(base64_encode($attacheContent)) . "\n\n"; } function setFrom($email,$name='none'){ $this->mail['from'] = $email; $this->mail['sender'] = $name; } function addTo($email){ if(is_string($email)){ $email = explode(',',$email); } foreach ($email as $id=>$mail){ if(!$this->_isMail($mail)){ unset($email[$id]); } } $this->mail['to'] = array_merge($this->mail['to'],$email); } function setContent($content,$content_type='text/plain'){ $this->mail['content'] = $content; $this->mail['content_type'] = $content_type=='text/html'?'text/html':'text/plain'; } function setSubject($subject){ $this->mail['subject'] = $subject; } function send(){ $this->mail['headers'] = "Content-Type: ". $this->mail['content_type']."\n"; $this->mail['headers'] .= "\n" . $this->mail['content'] . "\n\n"; if($this->mail['attaches']!=''){ $this->mail['headers'] = "Mime-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"".$this->mail['boundary']."\"\n\nThis is a multi-part message in MIME format.\n\n" . "--" . $this->mail['boundary'] . "\n" . $this->mail['headers'] . $this->mail['attaches'] . "--" . $this->mail['boundary'] . "--\n"; } $this->mail['headers'] = "From: ".$this->mail['sender']." <".$this->mail['from'].">\n" //."Cc: [email protected]\r\n" //."Bcc: [email protected]\r\n" .$this->mail['headers']; return @mail(@join(',',$this->mail['to']), $this->mail['subject'],' ',$this->mail['headers']); } function _isMail($mail){ return preg_match("/^[-a-zA-Z0-9_\.]+\@([0-9A-Za-z][0-9A-Za-z-]+\.)+[A-Za-z]{2,4}$/", $mail); } function clear(){ unset($this->mail); }} smarty分配数据的问题 跪求 如何更快的学会 PHP语言呢? 高分:htm中有frame,用smarty显示却不正常的问题。 端口问题,请求解决! php调用com组件,如何能查看到它的所有方法和属性啊 使用php编写socket服务端程序,不知道为什么读不出socket中的数据,请各位大虾指点,先行谢过 数据导到excel表格问题 php配制问题 header函式怎样将数组参数传送到下一页? apache这样配,为啥404服务不起作用呢 求一SQL语句! 网页过期的问题
/* Mailer
** author: episome <webmaster(at)3ants.org>
** website: http://3ants.org
**/
class mailer{
var $mail = array();
function mailer(){
$this->mail['boundary'] = '===' . md5(uniqid('')) . '===';
$this->mail['content_type'] = 'text/plain';
$this->mail['attaches'] = '';
$this->mail['sender'] = 'none';
$this->mail['from'] = '[email protected]';
}
function addAttaches($attaches,$attacheContent=null){
if(is_null($attacheContent)){
if(is_string($attaches)){
$attaches = explode(',',$attaches);
}
foreach ($attaches as $attache){
if(!is_file($attache)){
continue;
}
$attacheContent = join('',file($attache));
$this->_addAttacheContent($attache,$attacheContent);
}
}else{
$this->_addAttacheContent($attaches,$attacheContent);
}
}
function _addAttacheContent($attache,$attacheContent){
$this->mail['attaches'] .= "--" . $this->mail['boundary'] . "\n";
$this->mail['attaches'] .= "Content-Type: application/octet-stream; name=\"" . basename($attache) . "\"\nContent-Transfer-Encoding: BASE64\nContent-Disposition: attachment; filename=\"" . basename($attache) . "\"\n";
$this->mail['attaches'] .= "\n" . chunk_split(base64_encode($attacheContent)) . "\n\n";
}
function setFrom($email,$name='none'){
$this->mail['from'] = $email;
$this->mail['sender'] = $name;
}
function addTo($email){
if(is_string($email)){
$email = explode(',',$email);
}
foreach ($email as $id=>$mail){
if(!$this->_isMail($mail)){
unset($email[$id]);
}
}
$this->mail['to'] = array_merge($this->mail['to'],$email);
}
function setContent($content,$content_type='text/plain'){
$this->mail['content'] = $content;
$this->mail['content_type'] = $content_type=='text/html'?'text/html':'text/plain';
}
function setSubject($subject){
$this->mail['subject'] = $subject;
}
function send(){
$this->mail['headers'] = "Content-Type: ". $this->mail['content_type']."\n";
$this->mail['headers'] .= "\n" . $this->mail['content'] . "\n\n";
if($this->mail['attaches']!=''){
$this->mail['headers'] = "Mime-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"".$this->mail['boundary']."\"\n\nThis is a multi-part message in MIME format.\n\n"
. "--" . $this->mail['boundary'] . "\n"
. $this->mail['headers']
. $this->mail['attaches']
. "--" . $this->mail['boundary'] . "--\n";
}
$this->mail['headers'] = "From: ".$this->mail['sender']." <".$this->mail['from'].">\n"
//."Cc: [email protected]\r\n"
//."Bcc: [email protected]\r\n"
.$this->mail['headers'];
return @mail(@join(',',$this->mail['to']), $this->mail['subject'],' ',$this->mail['headers']);
}
function _isMail($mail){
return preg_match("/^[-a-zA-Z0-9_\.]+\@([0-9A-Za-z][0-9A-Za-z-]+\.)+[A-Za-z]{2,4}$/", $mail);
}
function clear(){
unset($this->mail);
}
}