Email send processing, support multiplayer forwarding, accessories, HTML mail

xiaoxiao2021-03-06  51

# 使用 使用 举: # cd.php "); # $ email = new tool_email (); # $ email-> setto (" gzdkj@163.net "); # $ email-> setfrom (" gzdkj @ 163.NET "); # $ email-> mailcc =" arnold@addcn.com "; # $ email-> mailimg =" f_4.jpg "; # $ email-> maiLattachments =" f_4.jpg "; # $ Email-> setsubject ("Test!"); # $ Email-> settext ("Test!"); # $ Email-> setHTML (" test ! "); # ix ($ email-> send ()) {echo" ok ";} Class Tool_Email {var $ Mailto = ""; // mail send address list var $ mailcc = "; // Cc message list var $ mailbcc =" "; // Anonymous email address list var $ mailfrom =" "; // sender mail Address VAR $ MAILSUBJECT = ""; // Mail Topic var $ mailtext = ""; // Pure text mail content var $ mailhtml = ""; // html text message VAR $ mailimg = "" "; // mail picture VAR $ maintachments =" "; // message attachment list

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- - Function: Setting Email Send Address and checks $ INADDRESS for Email Address: The email address list you want to send. -------------------------------------------------- -------------------------------------------------- --- * / Function setto ($ INADDRESS) {$ AddressArray = EXPLODE (",", $ INADDRESS; for ($ I = 0; $ i Checkemail ($ AddressArray [$ I]) == false) Return False;} $ this-> mailto = Implode ($ addressArray, ","); return true;} / * ------------ -------------------------------------------------- ---------------------------------------- Function: Set the Email Cc address, and Email address format Check $ INADDRESS: The list of email addresses to be copied. -------------------------------------------------- -------------------------------------------------- --- * / Function SETCC ($ INADDRESS) {$ AddressArray = Explode (",", $ INADDRESS; for ($ I = 0; $ i = 0; $ i ) {= ($ this- > Checkemail ($ addressArray [$ I]) == false) Return False;} $ this-> mailcc = Implode ($ addressArray, ","

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- - Function: Setting Email Anonymous Send Mail Address List and checks $ INADDRESS for email address format: An anonymous email address list. -------------------------------------------------- -------------------------------------------------- --- * / Function SETBCC ($ INADDRESS) {$ AddressArray = EXPLODE (",", $ INADDRESS; for ($ I = 0; $ i Checkemail ($ addressArray [$ I]) == false) Return False;} $ this-> mailbcc = @ a a r;} / * ---------- -------------------------------------------------- ---------------------------------------- Function: Set Email sender email address, and Check the Email address format $ INADDRESS: Send a mail address. -------------------------------------------------- -------------------------------------------------- --- * / Function setFrom ($ INADDRESS) {IF ($ this-> checkemail ($ this-> mailfrom = $ inaddress; return true;} return false;}

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- - Function: Setting Email Email Topic $ Insubject: Mail Theme. -------------------------------------------------- -------------------------------------------------- --- * / Function setsubject ($ insubject) {if (strlen ($ inSubject)> 0) {$ this-> mailsubject = EREGI_REPLACE ("/ n", ", $ insubject); return true;} Return false;}

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- - Function: Setting Email Plain text Format Mail content $ INTEXT: Plain text format email content. -------------------------------------------------- -------------------------------------------------- --- * / function settext ($ intext) {if (Strlen (Trim ($ xt))> 0) {$ this-> mailtext = $ intext; return true;} Return False;} / * ----- -------------------------------------------------- -------------------------------------------- function: Set Email HTML Format Mail content $ INHTML: HTML format mail content. -------------------------------------------------- -------------------------------------------------- --- * / Function Sethtml ($ inhtml) {IF (Strlen (Trim ($ inhtml))> 0) {$ this-> mailhtml = $ inhtml; return true;} Return false;}

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- - Function: Setting the image in Email Mail $ images: Images in the email. -------------------------------------------------- -------------------------------------------------- --- * / Function Sethtmlimages ($ images) {IF (Strlen (Trim ($ images))> 0) {$ this-> mailimg = $ images; return true;} Return False;}

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- - Function: Set annex $ INATTACHMENTS: Mail in an email message. -------------------------------------------------- -------------------------------------------------- --- * / Function settachments ($ INATTACHMENTS) {IF (Strlen (Trim ($ INATTACHMENTS))> 0) {$ this-> mailattachments = $ inattachments; return true;} Return false;} / * ----- -------------------------------------------------- ------------------------------------------- Function: Check Email format The correctness is $ INADDRESS: Email address. -------------------------------------------------- -------------------------------------------------- --- * / Function Checkemail ($ INADDRESS) {$ Check_Result = (EREG ("^ [^ @] @ ([A-ZA-Z0-9 / -] /.) ([A-ZA-Z0 -9 / -] {2} | NET | COM | GOV | MIL | ORG | EDU | INT) / $ ", $ INADDRESS)); if (! $ Check_result) {$ this-> err_num =" 402 "; Return $ Check_Result;

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- - Function: Get a random split string $ OFFSET: offset. -------------------------------------------------- -------------------------------------------------- --- * / Function Getrandomboundary ($ OFFSET = 0) {SRAND (Time () $ OFFSET); // Sets the chaos seed Return ("----". (MD5 ()))); / / Get a string of 4-bit to 32-bit yuan}

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- - Function: Get file type $ INFILENAME: Archive name. -------------------------------------------------- -------------------------------------------------- --- * / Function getContentType ($ INFILENAME) {$ INFILENAME = BaseName ($ INFILENAME); // Remove the file name IF without the path (STRRCHR ($ INFILENAME, ".") == false) {// Check Whether there is a secondary file name Return "Application / OCTET-stream";} $ extension = STRRCHR ($ INFILENAME, "."); // Deperse the file type Switch ($ extension) {case ".gif": Return "image / gif"; case ".gz": return "Application / X-gzip"; Case ".htm": return "text / html"; case ".php": return "text / html"; casse ". SHTML ": return" text / html "; case" .html ": return" text / html "; case" .jpg ": return" image / jpeg "; case" .tar ": return" Application / X-Tar " Case ".txt": return "text / plain"; case ".zip": return "Application / Zip"; default: return "Application / OcTet-Stre AM ";} return" Application / OcTet-stream ";

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- - Function: Formatted text Headload Information ----------------------------------------- -------------------------------------------------- ------------- * / function formattextheader () {$ outtextheader = ""; $ outtextheader. = "Content-type: text / place; charset =". Char_set. "/ N"; $ OTTEXTHEADER. = "Content-Transfer-Encoding: 7bit / N / N"; $ outtextheader. = $ this-> mailtext. "/ n"; return $ OTTEXTHEADER;} / * ---------- -------------------------------------------------- ---------------------------------------- Function: Format HTML header information - -------------------------------------------------- -------------------------------------------------- - * / Function FormathtmlHeader () {$ OuthtmlHeader = ""; $ OUTHTMLHEADER. = "Content-type: text / html; charset =". CHAR_SET. "/ N"; $ OUTHTMLHEADER. = "Content-Transfer-Encoding: 7bit / N / N "; $ Outhtmlheader. = $ This-> mailhtml. "/ N"; return $ outhtmlheader;}

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- - Function: Formatted Picture Header Information $ INFILELOCATION: File Location. -------------------------------------------------- -------------------------------------------------- --- * / Function FormatiMGHeader ($ InfileLocation) {$ outimgheader = ""; $ contentty = $ this-> getContentType ($ INFILELOCATION); / / Depending on the file sub-file Name Get file type // Format Head Information $ OutImGheader = "Content-Type:" $ contentType. "; / N"; $ outimgheader. = 'Name = "'. BaseName ($ INFILELOCATION). '"' '"/ N"; $ outimgheader. = "Content- TRANSFER-ENCODING: BASE64 / N "; $ OTIMGHEADER. =" Content-ID: <". BaseName ($ INFILELOCATION)."> / N / n "; Exec (" UUENCODE -M $ InfileLocation Nothing_out ", $ RETURNARRAY); For ($ I = 1; $ i <($ RETURNARRAY)); $ I ) {// Add value returned by each row $ outimgheader. = $ RETURNARRAY [$ I]. "/ n";} $ OUTIMGHEADER. = "/ N"; return $ outimgheader;} / * ------------------------------------- -------------------------------------------------- ------------- Function: Format Accessories Head Information $ INFILELOCATION: File Location.

-------------------------------------------------- -------------------------------------------------- --- * / Function FormattachmentHeader ($ INFILELOCATION) {$ OuttTachmentHeader = ""; $ contenttype = $ this-> getContentType ($ INFILELOCATION); // Deperse the file type if (EREG ("Text", $ CONTENTTYPE)) {// If the content type is the standard 7-bit encoding $ OutttachmentHeader. = "Content-Type:"; $ OutttachmentHeader. = 'Name = "'. Basename ($". . inFileLocation) ' "'." / n "; $ outAttachmentHeader =." Content-Transfer-Encoding: 7bit / n "; $ outAttachmentHeader =." Content-Disposition: attachment; / n "; $ outAttachmentHeader = 'filename =. "'" "/ n / n"; $ textfile = fopen ($ INFILELOCATION, "R"); while (! Feof ($ TEXTFILE)) {$ OuttTachmentHeader. = FGETS ($ TEXTFILE, 1000);} fclose ($ textfile); $ outattachmentheader. = "/ n";} else {// non-TEXT file, 64-bit encoding $ outattachmenthead HEADER. = "Content-type:". $ ContentType. "; / N"; $ OutttachmentHeader. = 'Name = "'. Basename ($ InfileLocation). '"'. "/ N"; $ . outAttachmentHeader = "Content-Transfer-Encoding: base64 / n"; $ outAttachmentHeader = "Content-Disposition: attachment; / n"; $ outAttachmentHeader = 'filename = "' basename ($ inFileLocation).. '"'... "/ n / n"; EXEC (""

UUENCODE -M $ INFILOCATION NOTHING_OUT ", $ RETURNARRAY); For ($ I = 1; $ i <($ RETURNARRAY)); $ I ) {$ OutattachmentHeader. = $ RETURNARRAY [$ I]." / n "; }}}} /} / ********************************************************************************************************************************************** ************************************ Function: Send E-mail ******* *********************************************************** ******************************* / Function Send () {$ mailheader = ""; // Initialization Mail Headload Information IF ($ this-> mailcc! = "") $ mailheader. = "cc:". $ this-> mailcc. "/ n"; // mail header information Add Cc message list IF ($ this-> mailbcc! = ") $ mailheader = "BCC:" $ this-> mailbcc. "////-mail header information Add anonymous email address list if ($ this-> mailfrom! =") $ Mailheader. = "From:" $ this-> mailfrom. "/ n"; // Email header information Add sender email address

// Only pure text IF ($ this-> mailte! = "" && $ this-> mailhtml == "" && $ == ") {$ mail_result = @ mail ($ this-> mailto, $ this-> mailsubject, $ this-> mailtext, $ mailheader); if ($ mail_result) {$ this-> err_num = "400";} else {$ this-> err_num = "401";} returnome = "401"; } // html and text Else IF ($ this-> mailtext! = "" && $ this-> mailhtml! = "" && $ = "") {$ bodyboundary = $ this-> getrandomboundary () ; // Get a random split string $ textHeader = $ this-> formattextheader (); // formatted text header information $ htmlheader = $ this-> formatmlheader (); // Format HTML header information $ mailheader = "MIME-VERSION: 1.0 / N"; // Set MIME version $ mailheader. = "Content-type: multipart / alternative; //); // Establish a primary content header information and dividend string $ mailheader. = 'Boundary = "'" $ bodyboundary. '"; $ mailheader. =" / n / n / n "; $ mailheader. =" - ". $ bodyboundary." / n "; // increase the main Body content and dividend string $ mailheader. = $ TEXTHEADER; $ mailheader. = "-". $ Bodyboundary. "/ N"; $ mailheader. = $ Htmlheader; // increase HTML and end dividing string IF ($ this -> Mailimg! = "" "{$ IMGARRAY = EXPLODE (", ", $ this-> mailimg); // Add HTML content for containing pictures ($ I = 0; $ IMGARRAY); $ i ) {$ mailheader. = "

/N - "/ n"; $ mailheader. = $ this-> formatimghead ($ IMGARRAY [$ I]);}}} $ mailheader. = "/N--" #bodyboundary." - "; $ mail_result = @ mail ($ this-> mailto, $ this-> mailsubject," ", $ mailheader); // Send mail if ($ mail_result) {$ this-> err_num =" 400 ";} else {$ This-> err_num = "401";} Return $ MAIL_RESULT;}

// HTML and Text and Accessories ELSE IF ($ this-> mailtext! = "" && $ this-> mailhtml! = "" && $ this-> mailattachments! = "") {$ AttachmentBoundary = $ this-> getrandomboundary $ MailHeader. = "Content-Type: Multipart / Mixed; / N"; $ Mailheader. = 'Boundary = "'. $ Attachmentboundary. '"' '. "/ N / n"; $ mailheader. = "This is IS A Multi-Part Message in Mime Format./N "; $ mailheader. =" - "$ attachmentboundary." / n "; // text with html $ bodyboundary = $ this-> getrandomboundary (1); $ textHeader = $ this-> formattextheader (); $ htmlheader = $ this-> formathtmlhead (); $ mailheader. = "Mime-Version: 1.0 / n"; $ mailheader. = "Content-type: multipart / alternative; / n"; $ Mailheader. = 'Boundary = "'" $ bodyboundary. '"'; $ mailheader. =" / n / n / n "; $ mailheader. =" - ". $ bodyboundary." / n "; $ mailheader. = $ TEXTHEADER; $ mailheader. = "-" $ bodyboundary. "/ n"; $ mailheader; = $ htmlheader; if ($ this-> mailimg! = ") {$ IMGARRAY = EXPLODE (", ", $ THIS-> Mailimg); for ($ I = 0; $ I FormatImghead ($ IMGARRAY [$ I]);

转载请注明原文地址:https://www.9cbs.com/read-82874.html

New Post(0)