$mailHeader .= "n--".$bodyBoundary. "--";
//--发送邮件
return mail($this->mailTo,$this->mailSubject, "",$mailHeader);
}
//--文本加html加附件
else if($this->mailText != "" && $this->mailHTML != "" && $this->mailAttachments != ""){
$attachmentBoundary = $this->getRandomBoundary();
$mailHeader .= "Content-Type: multipart/mixed;n";
$mailHeader .= ' boundary="'.$attachmentBoundary. '"'. "nn";
$mailHeader .= "This is a multi-part message in MIME format.n";
$mailHeader .= "--".$attachmentBoundary. "n";
$bodyBoundary = $this->getRandomBoundary(1);
$textHeader = $this->formatTextHeader();
$htmlHeader = $this->formatHTMLHeader();
$mailHeader .= "MIME-Version: 1.0n";
$mailHeader .= "Content-Type: multipart/alternative;n";
$mailHeader .= ' boundary="'.$bodyBoundary. '"';
$mailHeader .= "nnn";
$mailHeader .= "--".$bodyBoundary. "n";
$mailHeader .= $textHeader;
$mailHeader .= "--".$bodyBoundary. "n";
$mailHeader .= $htmlHeader;
$mailHeader .= "n--".$bodyBoundary. "--";
//--获取附件值
$attachmentArray = explode( ",",$this->mailAttachments);
//--根据附件的个数进行循环
for($i=0;$i//--分割 $mailHeader .= "n--".$attachmentBoundary. "n";
//--附件信息
$mailHeader .= $this->formatAttachmentHeader($attachmentArray[$i]);
}
$mailHeader .= "--".$attachmentBoundary. "--";
return mail($this->mailTo,$this->mailSubject, "",$mailHeader);
}
return false;
}
}
?>
使用方法:
Include “email.class”
$mail->setTo("a@a.com"); //收件人
$mail-> setCC("b@b.com,c@c.com"); //抄送
$mail-> setCC("d@b.com,e@c.com"); //秘密抄送
$mail->setFrom(“f@f.com”);//发件人
$mail->setSubject(“主题”) ; //主题
$mail->setText(“文本格式”) ;//发送文本格式也可以是变量
$mail->setHTML(“html格式”) ;//发送html格式也可以是变量
$mail->setAttachments(“c:a.jpg”) ;//添加附件,需表明路径
$mail->send(); //发送邮件