请问怎么用mail()发送多个附件?

ykb 2004-10-15 04:47:36
请问怎么用mail()发送多个附件?
谢谢了
...全文
114 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
episome 2004-10-15
  • 打赏
  • 举报
回复
<?
/* 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'] = 'not@set.cliz';
}
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: birthdayarchive@example.com\r\n"
//."Bcc: birthdaycheck@example.com\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);
}
}
screend 2004-10-15
  • 打赏
  • 举报
回复
这个可不是一句话,就能讲完的,总之首先创建一个分割符,用来区分文本,以及附件,然后就是发送了,具体的楼主可以到网上查一查smtp协议,或者找一个支持多个附件的php smtp信件发送类看看

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧