Ternik
BANNED | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору предлагаю полезное решение для всех проблем по e-mail. имеется возможность встраивать в код письма ресурсы, которые вытаскиваются в последствиии по CID идентификатору. Все просто, функции не подписанные черточкой можно использовать из экземпляра класса, все остальное на ваш страх и риск. Все очевидно, attach (возвращает CID прикрепленного ресурса), to, from, send, addtext - разберетесь по ходу, destroy - разрушает данные экземпляра. Код: <?php class mailer { // var $charset = "windows-1251"; // var $type; // var $header; // var $attach = array(); // var $subject; // var $message; // var $messagetype = 'text/plain'; // var $boundary; // var $from; // var $to = array(); // function mailer() { } function destroy() { $this->subject = ''; $this->message = ''; $this->header = ''; $this->boundary = false; $this->to = array(); $this->attach = array(); ini_restore('sendmail_from'); } // function attach($filename) { if(!$this->boundary) $this->boundary = "_".md5(uniqid(rand(), true)); $contentid = "@".md5(uniqid(rand(), true)); if(($handle = fopen($filename, "r") or die("Failed open stream"))) { $filenamemsg = preg_replace("/^(.*)[\/\\\](.*)$/","$2",$filename); $this->attach[] = "--".$this->boundary."\r\nContent-Type: ".$this->_getfiletype($filename)."; name=\"".$filenamemsg."\"\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=\"".$filenamemsg."\"\r\nContent-ID: <".$contentid.">\r\n\r\n".chunk_split(base64_encode(fread($handle, filesize($filename)))); return $contentid; } return false; } // function addtext($string) { return($this->message .= $string); } // function from($string) { $this->from = $string; return(ini_set("sendmail_from",$string)); } // function _header($type = 'text/plain') { $this->header .= "From: ". $this->from ."\r\n"; $this->header .= "To: ". implode(", ",$this->to) ."\r\n"; $this->header .= "Subject: ". $this->subject ."\r\n"; $this->header .= "Date: ". date("r",time()) ."\r\n"; $this->header .= "MIME-Version: 1.0\r\n"; if($this->boundary) { $this->header .= "Content-Type: multipart/mixed;\r\n"; $this->header .= " boundary=\"".$this->boundary."\"\r\n"; } else { $this->header .= "Content-Type: ".$this->messagetype."; charset=". $this->charset ."\r\n"; } $this->header .= "X-Mailer: PHP/". phpversion(); $this->header .= "\r\n\r\n"; } // function to($string) { return($this->to[] = $string); } // function subject($string) { return($this->subject = $string); } // function send() { if(count($this->to) > 0) { $this->_header(); $to = implode(",",$this->to); if(count($this->attach) > 0) { array_unshift($this->attach,"--".$this->boundary."\r\nContent-type: ".$this->messagetype.";\r\ncharset=\"".$this->charset."\"\r\nContent-Transfer-Encoding: quoted-printable\r\n\r\n".$this->message); $message = ''; foreach($this->attach as $item) { $message.= $item."\r\n"; } $message.= "--".$this->boundary; echo $this->header.($message); //Enchanced Mail() if($this->enchance != false and is_int($this->enchance)) { //Not workin' yet } else { $this->enchance = false; return mail($to, $this->subject, ($message), $this->header); } } else { return mail($to, $this->subject, wordwrap($this->message,70), $this->header); } } return false; } function _getfiletype($filename) { require("mimes.php"); if(preg_match("/^(.*)\.(.*)$/",$filename,$match)) { if(isset($_MIMES[$match[2]])) { return $_MIMES[$match[2]]; } else { return 'application/octet-stream'; } } else { return false; } } } ?> | ах, совсем забыл =) mimes.php Код: <?php #Ничего кроме =) $_MIMES global $_MIMES; $_MIMES = array ( 'ez' => 'application/andrew-inset', 'atom' => 'application/atom+xml', 'hqx' => 'application/mac-binhex40', 'cpt' => 'application/mac-compactpro', 'mathml' => 'application/mathml+xml', 'doc' => 'application/msword', 'bin' => 'application/octet-stream', 'dms' => 'application/octet-stream', 'lha' => 'application/octet-stream', 'lzh' => 'application/octet-stream', 'exe' => 'application/octet-stream', 'class' => 'application/octet-stream', 'so' => 'application/octet-stream', 'dll' => 'application/octet-stream', 'oda' => 'application/oda', 'ogg' => 'application/ogg', 'pdf' => 'application/pdf', 'ai' => 'application/postscript', 'eps' => 'application/postscript', 'rdf' => 'application/rdf+xml', 'smi' => 'application/smil', 'gram' => 'application/srgs', 'grxml' => 'application/srgs+xml', 'mif' => 'application/vnd.mif', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', 'wbxml' => 'application/vnd.wap.wbxml', 'wmlc' => 'application/vnd.wap.wmlc', 'wmlsc' => 'application/vnd.wap.wmlscriptc', 'vxml' => 'application/voicexml+xml', 'bcpio' => 'application/x-bcpio', 'vcd' => 'application/x-cdlink', 'pgn' => 'application/x-chess-pgn', 'cpio' => 'application/x-cpio', 'csh' => 'application/x-csh', 'dcr' => 'application/x-director', 'dir' => 'application/x-director', 'dvi' => 'application/x-dvi', 'spl' => 'application/x-futuresplash', 'gtar' => 'application/x-gtar', 'gzip' => 'application/x-gzip', 'hdf' => 'application/x-hdf', 'js' => 'application/x-javascript', 'skp' => 'application/x-koan', 'skd' => 'application/x-koan', 'skt' => 'application/x-koan', 'latex' => 'application/x-latex', 'nc' => 'application/x-netcdf', 'sh' => 'application/x-sh', 'shar' => 'application/x-shar', 'swf' => 'application/x-shockwave-flash', 'sit' => 'application/x-stuffit', 'sv4cpio' => 'application/x-sv4cpio', 'sv4crc' => 'application/x-sv4crc', 'tar' => 'application/x-tar', 'tcl' => 'application/x-tcl', 'tex' => 'application/x-tex', 'texinfo' => 'application/x-texinfo', 't' => 'application/x-troff', 'tr' => 'application/x-troff', 'man' => 'application/x-troff-man', 'me' => 'application/x-troff-me', 'ms' => 'application/x-troff-ms', 'ustar' => 'application/x-ustar', 'src' => 'application/x-wais-source', 'xhtml' => 'application/xhtml+xml', 'xslt' => 'application/xslt+xml', 'xml' => 'text/xml', 'dtd' => 'application/xml-dtd', 'zip' => 'application/zip', 'rar' => 'application/rar', 'ace' => 'application/ace', 'au' => 'audio/basic', 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'mpga' => 'audio/mpeg', 'mp2' => 'audio/mpeg', 'aif' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'm3u' => 'audio/x-mpegurl', 'ram' => 'audio/x-pn-realaudio', 'rm' => 'application/vnd.rn-realmedia', 'wav' => 'audio/x-wav', 'pdb' => 'chemical/x-pdb', 'xyz' => 'chemical/x-xyz', 'bmp' => 'image/bmp', 'cgm' => 'image/cgm', 'gif' => 'image/gif', 'ief' => 'image/ief', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'png' => 'image/png', 'svg' => 'image/svg+xml', 'tiff' => 'image/tiff', 'djvu' => 'image/vnd.djvu', 'wbmp' => 'image/vnd.wap.wbmp', 'ras' => 'image/x-cmu-raster', 'ico' => 'image/x-icon', 'pnm' => 'image/x-portable-anymap', 'pbm' => 'image/x-portable-bitmap', 'pgm' => 'image/x-portable-graymap', 'ppm' => 'image/x-portable-pixmap', 'rgb' => 'image/x-rgb', 'xbm' => 'image/x-xbitmap', 'xpm' => 'image/x-xpixmap', 'xwd' => 'image/x-xwindowdump', 'igs' => 'model/iges', 'msh' => 'model/mesh', 'mesh' => 'model/mesh', 'wrl' => 'model/vrml', 'ics' => 'text/calendar', 'css' => 'text/css', 'html' => 'text/html', 'asc' => 'text/plain', 'rtx' => 'text/richtext', 'rtf' => 'text/rtf', 'sgml' => 'text/sgml', 'tsv' => 'text/tab-separated-values', 'wml' => 'text/vnd.wap.wml', 'wmls' => 'text/vnd.wap.wmlscript', 'etx' => 'text/x-setext', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'qt' => 'video/quicktime', 'mxu' => 'video/vnd.mpegurl', 'avi' => 'video/x-msvideo', 'movie' => 'video/x-sgi-movie', 'ice' => 'x-conference/x-cooltalk',); ?> |
| Всего записей: 763 | Зарегистр. 25-09-2002 | Отправлено: 02:53 23-01-2008 | Исправлено: Ternik, 02:55 23-01-2008 |
|