<?php Class Mail { Private $topic; Private $toaddr; Private $fromaddr; Private $CC; Private $content; Private $attach; Private $header; private $domain;//mailbox domain Private $msg; Private $filename; Private $filemime; Private $filestr; Private $boundary; Private $uniqid; Private $eol; The type of line break added at the end of each line function __construct () { $this->geteot ();//Generate End line break $this->getuniq_id (); $this->header= '; $this->attach= '; $this->cc= '; $this->msg= '; } Public Function getfromaddr () { return $this->fromaddr; } Public Function setfromaddr ($FROMADDR) { $this->fromaddr = $fromaddr; } Public Function Gettopic () { return $this->topic; } Public Function gettoaddr () { return $this->toaddr; } Public Function GETCC () { return $this->cc; } Public Function getcontent () { return $this->content; } Public Function Getattach () { return $this->attach; } Public Function Settopic ($topic) { $this->topic = mb_convert_encoding (Trim ($topic), ' UTF-8 ', ' auto '); } Public Function settoaddr ($TOADDR) { $this->toaddr = Trim ($TOADDR); } Public Function SETCC ($CC) { $this->cc = Trim ($CC); } Public Function SetContent ($content) { $this->content = mb_convert_encoding (Trim ($content), ' UTF-8 ', ' auto '); } Public Function Setattach ($attach) { $this->attach = Trim ($attach); } Public Function GetDomain () { return $this->domain; } Public Function SetDomain ($domain) { $this->domain = $domain;//The value entered is ' @domain. com ' } /* * Set line breaks based on system type */ Private Function Geteot () { if (Strtoupper (substr (php_os, 0, 3) = = ' WIN ') { $this->eol = "RN"; } elseif (Strtoupper (substr (php_os, 0, 3) = = ' MAC ')) { $this->eol= "R"; } else { $this->eol = "n"; } } Private Function Getboundary () { $this->boundary= '--'. SUBSTR (MD5 (Time (). Rand (1000,2000)), 0,16); } Private Function getuniq_id () { $this->uniqid= MD5 (Microtime (). Time (). Rand (1,100)); } Private Function Outputcommonheader () { $this->header. = ' from: '. $this->fromaddr. $this->eol; $this->header. = ' to: '. $this->toaddr. $this->eol; $this->header. = ' Subject: '. $this->topic. $this->eol; $this->header. = ' Message-id: < '. $this->uniqid. $this->domain. ' > '. $this->eol; $this->header. = ' mime-version:1.0 '. $this->eol; $this->header. = ' reply-to: '. $this->fromaddr. $this->eol; $this->header. = ' Return-path: '. $this->fromaddr. $this->eol; $this->header. = ' X-mailer:xmail System '. $this->eol; $this->header. = ' Content-disposition:inline '. $this->eol; } Private Function Mime_content_type ($f) { $temp = Trim (exec (' File-bi '. Escapeshellarg ($f))); $temp = preg_replace ('/s+/', ', ', $temp); $temp = Explode (", $temp); return $temp [0]; }//to determine the MIME type of a file /* * With CC only */ Private Function MAILWITHCC () { $this->header. = ' Cc: '. $this->cc. $this->eol; $this->header. = ' content-type:text/html; Charset=utf-8 '. $this->eol; $this->header. = ' content-transfer-encoding:8bit '. $this->eol; $this->msg = $this->content; if (Mail ($this->toaddr, $this->topic, $this->msg, $this->header)) { return 1; }else{ return 0; } } /* * $filedir need to be an absolute address */ Private Function AttachmentToBase64 ($filedir) { $this->filename = basename ($filedir); @ $fopen = fopen ($filedir, ' R '); $str = Fread ($fopen, FileSize ($filedir)); $str = Base64_encode ($STR); $this->filestr = $str; } /* * with attachments only */ Private Function Mailwithattach () { $this->attachmenttobase64 ($this->attach ); $this->header. = ' content-type:multipart/mixed boundary= '. Str_replace ('--', ', $this->boundary). $this->eol; $this->msg. = $this->eol. $this->boundary. $this->eol; $this->msg. = ' content-type:text/html; Charset=utf-8 '. $this->eol; $this->msg. = ' Content-disposition:inline '. $this->eol; $this->msg. = $this->eol. $this->content. $this->eol; $this->msg. = $this->boundary. $this->eol; $this->msg. = ' Content-type: '. $this->mime_content_type ($this->attach). $this->eol; $this->msg. = ' Content-disposition:attachment filename= '. $this->filename. ' " $this->eol; $this->msg. = ' content-transfer-encoding:base64 '. $this->eol; $this->msg. = $this->eol. $this->filestr. $this->eol; $this->msg. = $this->eol. $this->boundary. '--'; if (Mail ($this->toaddr, $this->topic, $this->msg, $this->header)) { return 1; }else{ return 0; } } /* * With accessories and CC */ Private Function Mailall () { $this->attachmenttobase64 ($this->attach); $this->header. = ' Cc: '. $this->cc. $this->eol; $this->header. = ' content-type:multipart/mixed boundary= '. Str_replace ('--', ', $this->boundary). $this->eol; $this->msg. = $this->eol. $this->boundary. $this->eol; $this->msg. = ' content-type:text/html; Charset=utf-8 '. $this->eol; $this->msg. = ' Content-disposition:inline '. $this->eol; $this->msg. = $this->eol. $this->content. $this->eol; $this->msg. = $this->boundary. $this->eol; $this->msg. = ' Content-type: '. $this->mime_content_type ($this->attach). $this->eol; $this->msg. = ' Content-disposition:attachment filename= '. $this->filename. ' " $this->eol; $this->msg. = ' content-transfer-encoding:base64 '. $this->eol; $this->msg. = $this->eol. $this->filestr. $this->eol; $this->msg. = $this->eol. $this->boundary. '--'; if (Mail ($this->toaddr, $this->topic, $this->msg, $this->header)) { return 1; }else{ return 0; } } /* * Without CC and accessories */ Private Function Mailsimple () { $this->header. = ' content-type:text/html; Charset=utf-8 '. $this->eol; $this->header. = ' content-transfer-encoding:8bit '. $this->eol; $this->msg = $this->content; if (Mail ($this->toaddr, $this->topic, $this->msg, $this->header)) { return 1; }else{ return 0; } } Public function Send () { if (Empty ($this->attach) &&empty ($this->cc)) { $this->outputcommonheader (); return $this->mailsimple (); }else if (empty ($this->attach)) { $this->outputcommonheader (); return $this->MAILWITHCC (); }else if (empty ($this->cc)) { $this->outputcommonheader (); $this->getboundary (); There are attachments to generate boundary return $this->mailwithattach (); }else if (!empty ($this->toaddr) &&!empty ($this->topic) &&!empty ($this->cc) &&! Empty ($this->content) &&!empty ($this->attach)) { $this->outputcommonheader (); $this->getboundary (); There are attachments to generate boundary return $this->mailall (); } } } |