请问怎么用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); }} 请教PHP报错的原因? http://localhost/ 为什么要连接计算机?用户名和密码指的是什么? Php\MySql如何把表中X个客户随机平均分配给A、B、C三个人!急! XAMPP不支持flv视频吗? 分号的快捷键是什么? 请帮忙 新人遇到了学php以来第一个难题,传值丢失 真是急死人了,怎样在js里调用PHP的结果呢? 关于加载已做好的多个摸版,高手替顶,请大家说说思路 问一个傻问题,为什么我局域网内用ip访问不大到............ 求一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);
}
}