
прафесар™
   
Профиль
Группа: Комодератор
Сообщений: 3014
Регистрация: 13.3.2003
Где: Венья, Пиетари
Репутация: нет Всего: 102
|
Вот мой измененный класс: Код | <? class Mail { // // +----------------------------------------------------------------------+ // | Mail, класс для отправки электронной почты с вложениями | // +----------------------------------------------------------------------+ // | Класс предназначен для отправки электронной почты с вложениями. | // | Класс автоматически распознает кодировку отправляемого сообщения и | // | переконвертирует его в заданную кодировку. | // | Поддерживается автоматическое определение типа MIME вложений. | // +----------------------------------------------------------------------+ // | Автор: Пинежанинов Иван <[email protected]> | // +----------------------------------------------------------------------+ // // v 1.01 18:42 01.11.2003 // // +----------------------------------------------------------------------+ // | Конфигурационные переменные: | // +----------------------------------------------------------------------+ var $from; var $to; var $subject; var $body; var $html_auto = false; var $html = true; var $cp = 'windows-1251'; var $cp_auto = false; var $cp_in; // +----------------------------------------------------------------------+ // | Конец конфигурационных переменных. | // +----------------------------------------------------------------------+ var $nl; var $parts = Array(); var $headers = Array(); function Mail() { substr(PHP_OS, 0, 3) == 'WIN' ? $this->nl = "\r\n" : $this->nl = "\n"; }
function add_attachment($file,$is_file=false) { if (file_exists($file)) { $file_name = basename($file); if (function_exists('mime_content_type')) { $ctype = mime_content_type($file); } else { $pathinfo = pathinfo($file); $mime = Array( 'rar' => 'application/x-tar', 'zip' => 'application/x-zip-compressed', 'asf' => 'video/x-ms-asf', 'wmv' => 'video/x-ms-wmv', 'aiff' => 'audio/aiff', 'au' => 'audio/basic', 'mid' => 'audio/mid', 'mp3' => 'audio/mpeg', 'wav' => 'audio/wav', 'wma' => 'audio/x-ms-wma', 'avi' => 'video/x-msvideo', 'ivf' => 'video/x-ivf', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'qt' => 'video/quicktime', 'mov' => 'video/quicktime', 'art' => 'image/x-jg', 'bmp' => 'image/bmp', 'gif' => 'image/gif', 'jpg' => 'image/jpg', 'swf' => 'application/futuresplash', 'tiff' => 'image/tiff', 'pdf' => 'application/pdf', 'html' => 'text/html', 'htm' => 'text/html', 'xls' => 'application/x-msexcel', 'doc' => 'application/msword', 'rtf' => 'application/msword', 'rtx' => 'text/richtext', 'xml' => 'text/xml', 'hta' => 'application/hta', 'css' => 'text/css', 'txt' => 'text/plain' ); isset($mime[$pathinfo['extension']]) ? $ctype = $mime[$pathinfo['extension']] : $ctype = 'application/octet - stream'; } $fopen = fopen($file, 'r'); $attachment = fread($fopen, filesize($file)); fclose($fopen); $this->parts[] = Array ( 'name' => $file_name, 'attachment' => $attachment, 'ctype' => $ctype, 'is_file' => $is_file ); return 0; } else { return 1; } }
function add_header($header) { $this->headers[] = trim($header); } function detect_cyr_charset($str) { $charsets = Array( 'k' => 0, 'w' => 0, 'd' => 0, 'i' => 0, 'm' => 0 ); for ($i = 0, $length = strlen($str); $i < $length; $i++) { $char = ord($str[$i]); //non-russian characters if ($char < 128 || $char > 256) continue; //cp866 if (($char > 159 && $char < 176) || ($char > 223 && $char < 242)) $charsets['d'] += 3; if (($char > 127 && $char < 160)) $charsets['d'] += 1; //koi8-r if (($char > 191 && $char < 223)) $charsets['k'] += 3; if (($char > 222 && $char < 256)) $charsets['k'] += 1; //win-1251 if ($char > 223 && $char < 256) $charsets['w'] += 3; if ($char > 191 && $char < 224) $charsets['w'] += 1; //mac if ($char > 221 && $char < 255) $charsets['m'] += 3; if ($char > 127 && $char < 160) $charsets['m'] += 1; //iso-8859-5 if ($char > 207 && $char < 240) $charsets['i'] += 3; if ($char > 175 && $char < 208) $charsets['i'] += 1; } arsort($charsets); return key($charsets); }
function cp_convert() { $cp_array = Array( 'windows-1251' => 'w', 'koi8-r' => 'k', 'iso8859-5' => 'i', 'x-cp866' => 'a', 'x-mac-cyrillic' => 'm' ); if ($this->cp_auto == true) { $from = $this->detect_cyr_charset($this->body); } else { isset($cp_array[$this->cp_in]) ? $from = $cp_array[$this->cp_in] : $from = 'w'; } isset($cp_array[$this->cp]) ? $to = $cp_array[$this->cp] : $to = 'k'; $this->subject = convert_cyr_string($this->subject, $from, $to); $this->body = convert_cyr_string($this->body , $from, $to); }
function build_part($part) { $attachment = chunk_split(base64_encode($part['attachment'])); $encoding = 'base64'; if ($part['is_file']) return 'Content-Disposition: attachment; filename="'.$part['name'] .'"' . $this->nl . 'Content-Transfer-Encoding: ' . $encoding . $this->nl . $this->nl . $attachment . $this->nl; $ct_id='Content-ID: <'.$part['name'].'>'; return $ct_id.$this->nl.'Content-Disposition: attachment; name="'.$part['name'] .'"' . $this->nl . 'Content-Transfer-Encoding: ' . $encoding . $this->nl . $this->nl . $attachment . $this->nl; }
function build_multipart() { $boundary = 'b' . md5(uniqid(time())); $multipart = 'Content-Type: multipart/mixed; boundary = ' . $boundary . $this->nl . $this->nl . 'This is a MIME encoded message.' . $this->nl . $this->nl . '--' . $boundary . $this->nl; $multipart .= 'Content-Type: text/'; if ($this->html_auto == true) { $pattern = "%</?\w+(\s[^>]*)?>%is"; preg_match($pattern, $this->body) == true ? $multipart .= 'html' : $multipart .= 'plain'; } else { $this->html == true ? $multipart .= 'html' : $multipart .= 'plain'; } $multipart .= '; charset=' . $this->cp . $this->nl . 'Content-Transfer-Encoding: 8bit' . $this->nl . $this->nl . $this->body . $this->nl . $this->nl . '--' . $boundary; $i = 0; $count = sizeof($this->parts); while ($i < $count) { $multipart .= $this->nl . $this->build_part($this->parts[$i]). '--' . $boundary; $i++; } return $multipart .= '--' . $this->nl; }
function send() { $this->cp_convert(); $headers = ''; empty($this->from) or $headers .= 'From: ' . $this->from . $this->nl; $i = 0; $count = sizeof($this->headers); while ($i < $count) { $headers .= $this->headers[$i] . $this->nl; $i++; } $headers .= 'MIME-Version: 1.0' . $this->nl; $headers .= $this->build_multipart(); $headers = 'Content-Type: text/html; charset=windows-1251 Content-Transfer-Encoding: 8bit '.$headers; return mail($this->to, $this->subject, '', $headers); } } ?>
|
Использование: Код | $mail = new Mail; $mail->subject = htmlspecialchars($MSG['title']); $mail->add_header ('X-Priority: '.$MSG['priority']);
// добавление вложений { $mail->add_attachment($folder.$fname,true); }
// замена картинок в письме { $mail->add_attachment("..".$imgs[$a]); $msg=str_replace('src="','src="cid:',$msg); $msg=str_replace("src='","src='cid:",$msg); }
|
Оригинал: Добавлено через 10 минут и 32 секунды-=Ustas=-, а где скачать эти самые: include('Mail.php'); include('Mail/mime.php');
Присоединённый файл ( Кол-во скачиваний: 3 )
stdMailer.php 11,26 Kb
--------------------
Каждый чилавек пасвоему праф...а памоему НЕТ!
|