图老师小编精心整理的一个可以发送附件及HTML格式邮件的PHP类希望大家喜欢,觉得好的亲们记得收藏起来哦!您的支持就是小编更新的动力~
【 tulaoshi.com - Web开发 】
一个用Php Class写的发信程序
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)这个类里显示了发送MIME的方法,也就是HTML格式信件和附件发送的问题。
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)/*
Mail: An object to encapsulate the sending of email. Allows user-specified
From: addresses, handles the encoding of attachments; conforms more or less to
MIME standards.. Uses sendmail to send the mail, mimencode to do the MIME
encoding, and zip to automatically zip attachments.
Contacting the author(s):
Brought to you by the team at Sequoia Softworks, http://www.sequoiasoft.com
Feel free to contact tony@sequoiasoft.com and tell us how you like it!
(Or to complain bitterly, report bugs, or suggest new features.)
Known shortcomings/bugs:
o guessMIMEType()only knows about a few MIME types. You can expand this as
you need.
o $mime_boundary in the Send() method should be randomly generated, but it
isn't likely to ever hurt anything in its current form
Example:
require("Mail.phtml");
$mymessage = new Mail();
$mymessage-from = "php3.script@www.somedomain.net";
$mymessage-to = "luckyuser@destination.org";
$mymessage-subject = "This is your lucky day";
$mymessage-headers["Reply-To"] = "webmaster@www.somedomain.net";
$mymessage-headers["X-Extra-Header"] = "Pointless Header v3.0";
$mymessage-body = "Doesn't it feel good to get mail?nEspecially with files
attached!n";
$mymessage-attachments[0] = "tarball.tar.gz";
$mymessage-attachments[1] = "images/smiling_countenance.gif";
$mymessage-attachments[2] = "/usr/share/reference/jargondict.html";
$mymessage-attachments[3] = "./core";
$mymessage-attachments[4] = "/etc/passwd"; //naughty naughty!!
$mymessage-ZipAttachments("your_files.zip"); //uncomment this to zip all
//the attachments into one big
//attachment.
$mymessage-Send();
*/
class Mail {
var $from; //The sender
var $to; //The recipient
var $subject; //The subject line
var $headers; //A hash of additional headers (headername = headervalue)
var $zipname; //The name of the file the attachments are zipped into
//($zipname == false if attachments are to be sent
//individually)
var $attachments; //An array of files to attach
var $body; //The body text of the message
//Mail constructor: initializes vars to default values. 'Nuff said.
function Mail() {
$this-from = "";
$this-to = "";
$this-subject = "";
$this-headers = array();
$this-zipname = false;
$this-attachments = array();
$this-body = "";
}
//Auxiliary method, used to guess a file's MIME type
//based on its extension. Doesn't know about too many
//extensions right now
function guessMIMEType($filename) {
//GUESS MIME TYPE
$filename = basename($filename);
if(strrchr($filename,".") == false) {
return("application/octet-stream");
}
$ext = strrchr($filename,".");
switch($ext) {
case ".gif":
return "image/gif";
break;
来源:http://www.tulaoshi.com/n/20160219/1620958.html
看过《一个可以发送附件及HTML格式邮件的PHP类》的人还看了以下文章 更多>>