PHP Receive mail class
Receivemail is a PHP class designed to receive mail, and supports email protocols such as POP3 and IMAP. You can receive mail and email attachments.
Chinese garbled solution
/** * Decode the subject of Chinese * * @param string $subject * @return sting */public function Subjectdecode ($subject) { $BEGINSTR = substr ($subject, 0, 5); if ($beginStr = =? ISO ') {$separator = ' =? Iso-2022-jp '; $toEncoding = ' iso-2022-jp ';} else {$separator = ' =? GB2312 '; $toEncoding = ' GB2312 ';} $encode = Strstr ($subject, $separator), if ($encode) {$explodeArr = explode ($separator, $subject); $length = Count ($ Explodearr); $subjectArr = Array (); for ($i = 0; $i < $length/2; $i + +) {$SUBJECTARR [$i] = $EXPLODEARR [$i * 2];IF (@ $ex plodearr[$i * 2 + 1]) {$SUBJECTARR [$i] = $EXPLODEARR [$i * 2 + 1];}} foreach ($subjectArr as $arr) {$subSubject = implode ($separator, $arr), if (count ($arr) = = 1) {$subSubject = $separator. $ Subsubject;} $begin = Strpos ($subSubject, "=?"); $end = Strpos ($subSubject, "? ="); $beginStr = "; $endStr ="; if ($end > 0) {if ($begin > 0) {$beginStr = substr ($sub Subject, 0, $begin);} if ((strlen ($subSubject)-$end) > 2) {$endStr = substr ($subSubject, $end + 2, StrlEn ($subSubject)-$end-2);} $str = substr ($subSubject, 0, $end-strlen ($subSubject)); $pos = Strrpos ($str, "?"); $str = substr ($str, $pos + 1, strlen ($STR)-$pos); $subSubject = $beginStr. Imap_base64 ($STR). $ENDSTR, $subSubjectArr [] = Iconv ($toEncoding, ' utf-8 ', $subSubject);//Mb_convert_encoding ($subSubject, ' utf-8 ', ' Gb2312,iso-2022-jp ');}} $subject = Implode ("', $SUBSUBJECTARR);} return $subject;}
if (Strtolower ($sender->mailbox)! = ' Mailer-daemon ' && strtolower ($sender->mailbox)! = ' postmaster ')
{$subject = $this->subjectdecode ($mail _header->subject);
Here's how to use it:
Connect (); If connection fails give error message and exit//read all letters $tot = $obj->gettotalmails (); Total mails in Inbox Return integer valueecho "received $tot Email::
"; for ($i = $tot; $i > 0; $i-) {$head = $obj->getheaders ($i); Read get message header information, return array * * Array key value is (Subject,to,tooth,tonameoth,from,fromname) echo "Subject::". $head [' Subject ']. "
"; echo" to:: ". $head [' to ']."
"; echo" cc:: ". $head [' tooth ']."
"; echo" From:: ". $head [' from ']."
"; echo" sender Name:: ". $head [' FromName ']."
"; Echo"
"; Echo"
*******************************************************************************************
echo $obj->getbody ($i); Message body $STR = $obj->getattach ($i, "./"); Gets the message attachment, with the returned file name separated by commas. For example. (Mailid, Path to store file) $ar = Explode (",", $str), foreach ($ar as $key + $value) echo ($value = = "")? "": "Atteched Fi Le:: ". $value. "
"; Echo"
------------------------------------------------------
";//$obj->deletemails ($i); Delete Mail from Mail box} $obj->close_mailbox (); Close Mail box?>
RECEIVEMAIL.CLASS.PHP requires IMAP module support.
\ n ";//display subjects of messagesfor ($i =1; $i <=; $i + +) { $header = Imap_header ($imap, $i); echo "Subject:", $header->subject, "
\ n ";} Imap_close ($imap);? >
Imap_append:?? Attach a string to the specified mailbox.
Imap_base64:?? Solution base64 Encoding.
Imap_body:?? Read the letter in the text.
Imap_check:?? ? Returns the mailbox information.
Imap_close:?? ? close the IMAP link.
Imap_createmailbox:?? ? create a new mailbox.
Imap_delete:?? ? flag to delete the message.
Imap_deletemailbox:?? Delete existing mailboxes.
Imap_expunge:?? ? Delete flagged messages.
Imap_fetchbody:?? Remove the specified part from the letter text.
Imap_fetchstructure:?? ? Gets the structure information for a letter.
Imap_header:?? ? Gets the header information for a letter.
imap_headers:??? Get header information for all letters.
imap_listmailbox:??? Get mailbox listing.
imap_listsubscribed:?? ? Gets the subscription mailbox listing.
Imap_mail_copy:?? Copy the specified letter to its mailbox.
Imap_mail_move:?? ? Move the specified letter to its mailbox.
imap_num_msg:??? Get the number of letters.
Imap_num_recent:?? To obtain a new number of incoming letters.
Imap_open:?? ? Open the IMAP link.
Imap_ping:?? ? Check if IMAP is connected.
Imap_renamemailbox:?? ? Change the name of the mailbox.
Imap_reopen:?? ? re-open the IMAP link.
Imap_subscribe:?? ? subscribe to the mailbox.
Imap_undelete:?? ? Cancels the deletion of the message flag.
Imap_unsubscribe:?? ? Cancel the subscription mailbox.
Imap_qprint:?? ? Convert the QP encoding to eight bits.
Imap_8bit:?? ? turn eight bits into QP encoded.
Imap_binary:?? ? turn eight bits into base64 encoding.
Imap_scanmailbox:?? Look for letters with or without a specific string.
Imap_mailboxmsginfo:?? ? Get the current mailbox information.
Imap_rfc822_write_address:?? ? e-mail address standardization.
Imap_rfc822_parse_adrlist:?? ? Resolve e-mail addresses.
Imap_setflag_full:?? ? Configure letter flags.
Imap_clearflag_full:?? ? Clear the letter flag.
Imap_sort:?? ? sort the letter headers.
Imap_fetchheader:?? ? Gets the original header.
Imap_uid:?? ? Get the letter uid.
Imap_getmailboxes:?? ? Get full details of the letter.
imap_getsubscribed:?? ? list all subscribed mailboxes.
Imap_msgno:?? ? Lists the serial letters of the UID.
Imap_search:?? Search for a letter of the specified standard.
Imap_last_error:?? ? The last error message.
Imap_errors:?? ? All the error messages.
Imap_alerts:?? ? All the warning messages.
Imap_status:?? ? The current status information.
1/F Hdnlove 2012-04-10
Hello, I'd like to ask. I use Receivemail to receive the message how to get data when the load is very slow each time? Do you have any way to solve it?