Здравствуйте! Несколько дней искал в интернете хороший класс для работы с почтой по imap, видел много классов, но все они были сырые, где-то нет перекодировки, где-то нет возможности работать с вложениями, и тп. В результате сего практически написал свой (из кусков) и теперь осталось поправить пару ошибок, которые вылетают при выполнении скрипта, если вы мне это положите сделать, то я буду Вам примного благодарен. Сам я не силен в ООП, отсюда и непонимание таких ошибок. Прошу внимательно посмотреть на свойство $p. Мне кажется что все дело в нём. Мой скрипт: Код (Text): <?php header('Content-Type: text/html; charset=utf-8'); require_once 'htmltotext.php'; ?> <html> <head> <meta charset="utf-8"> <title>--</title> <style> body { font: 8pt sans-serif; } </style> <script src="../js/jquery-1.9.1.js"></script> <script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script> </head> <body> <?php $box = new MailClient; $box->user("mail@bk.ru","pass"); $box->server("imap.mail.ru","993","imap/ssl/novalidate-cert"); //$box->user("mail@gmail.com","pass"); //$box->server("imap.gmail.com","993","imap/ssl/novalidate-cert"); $box->open(); $totalCount = $box->count(); echo 'Total '.$totalCount .' messages<br>'; for ($i=$totalCount; $i>0; $i--) { $box->getmsg($i); //$plainmsg= quoted_printable_encode($plainmsg, true); //$htmlmsg= iconv('KOI8-R','utf-8',$htmlmsg); //$body = quoted_printable_encode_2($body); echo 'Text: '.$box->getText().'<br><br>'; //echo 'HTML: '.convert_html_to_text_rm($box->getHtml()).'<br><br>'; } //echo $plainmsg; class MailClient { public $server; public $port = 110; public $type = "pop3"; public $count; public $msg; private $user; private $pass; private $box; public $charset; public $htmlmsg; public $plainmsg; public $attachments; public $p; public function __construct() { if (!extension_loaded("imap")) { if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { dl('php_imap.dll'); } else { dl('php_imap.so'); } if (!extension_loaded("imap")) { $this->error("Could not load required extension... Please install extansion."); } } } public function getHtml() { return $this->htmlmsg; } public function getText() { return $this->plainmsg; } public function getcharset() { return $this->charset; } public function user($user, $pass) { $this->user = $user; $this->pass = $pass; } public function server($server, $port, $type) { $this->server = $server; $this->port = $port; $this->type = $type; } public function open() { $this->box = @imap_open("{".$this->server.":".$this->port."/".$this->type."}INBOX", $this->user, $this->pass); if($this->box) { return true; } if (imap_last_error()) { $this->error(imap_last_error()); } else { $this->error("Couldn't open stream ".$this->server.":".$this->port."..."); } return true; } public function select($id) { $this->msg = $id; return imap_headerinfo($this->box, $id); } public function count() { $this->count = imap_num_msg($this->box); return $this->count; } public function getmsg($id) { $this->msg = $id; $this->htmlmsg = $this->plainmsg = $this->charset = ''; // input $mbox = IMAP stream, $mid = message id // output all the following: $this->attachments = array(); // HEADER $h = imap_header($this->box, $this->msg); // add code here to get date, from, to, cc, subject... // BODY $s = imap_fetchstructure($this->box, $this->msg); if (!$s->parts) { // simple $this->p = $s; $this->partno = 0; $this->getpart(); // pass 0 as part-number } else { // multipart: cycle through each part foreach ($s->parts as $partno0=>$p) { $this->p = $p; $this->partno = $partno0+1; $this->getpart(); } } } public function getpart() { // $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple // DECODE DATA $p = $this->p; $data = ($this->partno)? imap_fetchbody($this->box, $this->msg, $this->partno): // multipart imap_body($this->box, $this->msg); // simple // Any part may be encoded, even plain text messages, so check everything. if ($p->encoding==4) $data = quoted_printable_decode($data); elseif ($p->encoding==3) $data = base64_decode($data); // PARAMETERS // get all parameters, like charset, filenames of attachments, etc. $params = array(); if ($p->parameters) foreach ($p->parameters as $x) $params[strtolower($x->attribute)] = $x->value; if ($p->dparameters) foreach ($p->dparameters as $x) $params[strtolower($x->attribute)] = $x->value; // ATTACHMENT // Any part with a filename is an attachment, // so an attached text file (type 0) is not mistaken as the message. if ($params['filename'] || $params['name']) { // filename may be given as 'Filename' or 'Name' or both $filename = ($params['filename'])? $params['filename'] : $params['name']; // filename may be encoded, so see imap_mime_header_decode() $this->attachments[$filename] = $data; // this is a problem if two files have same name } // TEXT if ($p->type==0 && $data) { // Messages may be split in different parts because of inline attachments, // so append parts together with blank row. if (strtolower($p->subtype)=='plain') $this->plainmsg .= trim($data) ."\n\n"; else $this->htmlmsg .= $data ."<br><br>"; $this->charset = $params['charset']; // assume all parts are same charset } // EMBEDDED MESSAGE // Many bounce notifications embed the original message as type 2, // but AOL uses type 1 (multipart), which is not handled here. // There are no PHP functions to parse embedded messages, // so this just appends the raw source to the main message. elseif ($p->type==2 && $data) { $this->plainmsg .= $data."\n\n"; } // SUBPART RECURSION if ($p->parts) { foreach ($p->parts as $partno0=>$p2) { $this->p = $p2; $this->partno = $this->partno.'.'.($partno0+1); $this->getpart(); // 1.2, 1.2.1, etc. } } } public function delete($id) { imap_delete($this->box, $id); imap_expunge($this->box); } public function error($error) { echo $error; exit(); } public function close() { imap_close($this->box); } } ?> </body> </html> Ошибки за 1 выполнение скрипта: Код (Text): 2013/03/02 09:34:02 [error] 12481#0: *3 FastCGI sent in stderr: "PHP message: PHP Notice: Undefined property: stdClass::$dparameters in /proj/my_service/server/ssl-server/testmail.php on line 157 PHP message: PHP Notice: Undefined index: filename in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined index: name in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined property: stdClass::$parts in /proj/my_service/server/ssl-server/testmail.php on line 192 PHP message: PHP Notice: Undefined property: stdClass::$dparameters in /proj/my_service/server/ssl-server/testmail.php on line 157 PHP message: PHP Notice: Undefined index: filename in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined index: name in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined property: stdClass::$parts in /proj/my_service/server/ssl-server/testmail.php on line 192 PHP message: PHP Notice: Undefined property: stdClass::$dparameters in /proj/my_service/server/ssl-server/testmail.php on line 157 PHP message: PHP Notice: Undefined index: filename in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined index: name in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined property: stdClass::$parts in /proj/my_service/server/ssl-server/testmail.php on line 192 PHP message: PHP Notice: Undefined property: stdClass::$dparameters in /proj/my_service/server/ssl-server/testmail.php on line 157 PHP message: PHP Notice: Undefined index: filename in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined index: name in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined property: stdClass::$parts in /proj/my_service/server/ssl-server/testmail.php on line 19 2013/03/02 09:34:02 [error] 12481#0: *3 FastCGI sent in stderr: "164 PHP message: PHP Notice: Undefined index: name in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined property: stdClass::$parts in /proj/my_service/server/ssl-server/testmail.php on line 192 PHP message: PHP Notice: Undefined property: stdClass::$dparameters in /proj/my_service/server/ssl-server/testmail.php on line 157 PHP message: PHP Notice: Undefined index: filename in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined index: name in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined property: stdClass::$parts in /proj/my_service/server/ssl-server/testmail.php on line 192 PHP message: PHP Notice: Undefined property: stdClass::$dparameters in /proj/my_service/server/ssl-server/testmail.php on line 157 PHP message: PHP Notice: Undefined index: filename in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined index: name in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined property: stdClass::$parts in /proj/my_service/server/ssl-server/testmail.php on line 192 PHP message: PHP Notice: Undefined property: stdClass::$dparameters in /proj/my_service/server/ssl-server/testmail.php on line 157 PHP message: PHP Notice: Undefined index: filename in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined index: name in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined property: stdClass::$parts in /proj/my_service/server/ssl-server/testmail.php on line 192 PHP message: PHP Notice: Undefined property: stdClass::$dparameters in /proj/my_service/server/ssl-server/testmail.php on line 157 PHP message: PHP Notice: Undefined index: filename in /proj/my_service/server/ssl-server/testmail.php on lin 2013/03/02 09:34:04 [error] 12481#0: *3 FastCGI sent in stderr: "e: PHP Notice: Undefined property: stdClass::$parts in /proj/my_service/server/ssl-server/testmail.php on line 192 PHP message: PHP Notice: Undefined property: stdClass::$dparameters in /proj/my_service/server/ssl-server/testmail.php on line 157 PHP message: PHP Notice: Undefined index: filename in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined index: name in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined property: stdClass::$parts in /proj/my_service/server/ssl-server/testmail.php on line 192 PHP message: PHP Notice: Undefined property: stdClass::$dparameters in /proj/my_service/server/ssl-server/testmail.php on line 157 PHP message: PHP Notice: Undefined index: filename in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined index: name in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined property: stdClass::$parts in /proj/my_service/server/ssl-server/testmail.php on line 192 PHP message: PHP Notice: Undefined property: stdClass::$dparameters in /proj/my_service/server/ssl-server/testmail.php on line 157 PHP message: PHP Notice: Undefined index: filename in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined index: name in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined property: stdClass::$parts in /proj/my_service/server/ssl-server/testmail.php on line 192 PHP message: PHP Notice: Undefined property: stdClass::$dparameters in /proj/my_service/server/ssl-server/testmail.php on line 157 PHP message: PHP Notice: Undefined index: filename in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP message: PHP Notice: Undefined index: name in /proj/my_service/server/ssl-server/testmail.php on line 164 PHP mess 2013/03/02 09:34:04 [error] 12481#0: *3 upstream sent too big header while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: xxx.xxx.xxx.xxx, request: "GET /testmail.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "xxx.ru" Спасибо!