<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] ## 常用函數 函數 ``` imap_open // 連接函數 imap_num_msg // 獲取當前郵箱中的郵件數量 imap_num_recent //獲取當前郵箱中的新郵件數量 imap_check // 返回當前郵箱信息 imap_setflag_full // 設置郵箱標記 imap_clearflag_full //清楚標記 imap_delete //刪除郵箱 imap_undelete // 取消標記未刪除的郵箱 imap_expunge //刪除標記刪除的所有消息 imap_headerinfo // 獲取單個郵箱元數據 imap_fetchheader //獲取單個或多個頭信息 imap_fetch_overview // 閱讀給定消息的標題中的信息概述 imap_fetchbody // 獲取郵箱正文,第三個參數為1,表示獲取正文,與 imap_body 相似 imap_body // 通過郵箱索引獲取郵箱body imap_mime_header_decode // 解析元數據 imap_msgno // 通過uid 獲取消息序列 imap_uid //給定消息序列號的UID imap_search // 搜索郵箱 ``` 常量 ``` // FLAGS define('SE_NOPREFETCH', 4); define('SO_FREE', 8); define('SO_NOSERVER', 8); define('SA_MESSAGES', 1); define('SA_RECENT', 2); define('SA_UNSEEN', 4); define('SA_UIDNEXT', 8); define('SA_UIDVALIDITY', 16); define('SA_ALL', 31); ``` ## 注意事項 很多函數帶 有 flag 可以把 msggno 的參數設置為 uid ``` imap_fetch_overview($inbox,10585,FT_UID) ``` ## 示例 ### imap_status 郵箱狀態 ``` $status = imap_status($inbox, $hostname, SA_ALL); //object(stdClass)#2 (6) { // ["flags"]=> // int(31) // ["messages"]=> // int(9599) // ["recent"]=> // int(0) // ["unseen"]=> // int(4) // ["uidnext"]=> // int(10585) // ["uidvalidity"]=> // int(1357024812) //} ``` - uidnext 獲取下一封右鍵的 唯一值 uid - messages 獲取總數 - recent 新郵箱 - unseen 未讀郵箱 - uidvalidity 郵箱的 UID 有效性 - flags 為郵箱的標記 ``` define('SE_NOPREFETCH', 4); define('SO_FREE', 8); define('SO_NOSERVER', 8); define('SA_MESSAGES', 1); define('SA_RECENT', 2); define('SA_UNSEEN', 4); define('SA_UIDNEXT', 8); define('SA_UIDVALIDITY', 16); define('SA_ALL', 31); ``` ### imap_append `imap_append` 函數并不能直接用來發送電子郵件,但可以用于將電子郵件添加到指定郵箱的“已發送”文件夾。為了實現發送電子郵件并記錄在 IMAP 服務器上的“已發送”文件夾,可以先使用 SMTP 協議發送電子郵件,然后使用 `imap_append` 將該郵件保存到“已發送”文件夾 ``` // IMAP 服務器配置 $hostname = '{imap.qq.com:993/ssl}INBOX'; $username = '26xxxx304@qq.com'; $password = 'gzrxxxibb'; // 打開 IMAP 連接 $inbox = imap_open($hostname, $username, $password,OP_READONLY) or die('Cannot connect to mail server: ' . imap_last_error()); // 構造郵件 $message = "From: sender@qq.com\r\n"; $message .= "To: 26xxx3304@qq.com\r\n"; $message .= "Subject: Test message\r\n"; $message .= "\r\n"; $message .= "This is a test message.\r\n"; // 追加郵件到郵箱 if (imap_append($inbox, $hostname, $message)) { echo "Message appended successfully."; } else { echo "Failed to append message: " . imap_last_error(); } ``` ### imap_body / imap_fetchbody 獲取郵箱內容 imap_body ``` // 打開 IMAP 連接 $inbox = imap_open($hostname, $username, $password,OP_READONLY) or die('Cannot connect to mail server: ' . imap_last_error()); $num = imap_num_msg($inbox); // 獲取郵箱總數 // 獲取第二新的郵箱 $imap_body = imap_body($inbox, $num-1); var_dump($imap_body); //"This is a test message. ``` imap_fetchbody ``` $msg_number = 1; $section = "1"; // 1 表示獲取消息本體 $body = imap_fetchbody($imap_stream, $msg_number, $section); if ($body !== false) { echo "Email body:\n"; echo $body; } else { echo "Failed to fetch email body: " . imap_last_error(); } ``` ### imap_check ``` $stdClass = imap_check($inbox); var_dump($stdClass); object(stdClass)#2 (5) { ["Date"]=> string(30) "Tue, 2 Jul 2024 15:05:04 +0800" ["Driver"]=> string(4) "imap" ["Mailbox"]=> string(70) "{imap.qq.com:993/imap/notls/ssl/readonly/user="26xxx04@qq.com"}INBOX" ["Nmsgs"]=> int(9601) ["Recent"]=> int(0) } ``` ### imap_setflag_full/ imap_clearflag_full ``` 常見標志 \\Seen:郵件已讀標志。 \\Answered:郵件已回復標志。 \\Flagged:郵件標記為重要標志。即收藏 \\Deleted:郵件標記為刪除標志。 \\Draft:郵件標記為草稿標志。 ``` 示例 ``` // 指定郵件序號范圍和標志 $sequence = '1:3'; // 清除第一到第三封郵件的標志,也可以設置一個 $flag = '\\Seen'; // \Seen 表示已讀標志 if (imap_setflag_full($imap_stream, $sequence, $flag)) { echo "Flags set successfully."; } else { echo "Failed to set flags: " . imap_last_error(); } // 清除標志 if (imap_clearflag_full($imap_stream, $sequence, $flag)) { echo "Flags cleared successfully."; } else { echo "Failed to clear flags: " . imap_last_error(); } ``` ### imap_headerinfo / imap_fetchheader / imap_fetch_overview <details> <summary>imap_headerinfo 獲取單個,返回一個對象,包含f豐富的字段信息</summary> ``` $imap_body = imap_headerinfo($inbox, $num); // 獲取最新郵箱 var_dump($imap_body); //object(stdClass)#2 (23) { // ["date"]=> // string(36) "Tue, 2 Jul 2024 15:10:55 +0800 (CST)" // ["Date"]=> // string(36) "Tue, 2 Jul 2024 15:10:55 +0800 (CST)" // ["subject"]=> // string(36) "=?utf-8?B?5q+P5pel5L+h55So566h5a62?=" // ["Subject"]=> // string(36) "=?utf-8?B?5q+P5pel5L+h55So566h5a62?=" // ["message_id"]=> // string(82) "<714080548.31948858.1719904255037.JavaMail.cmbchina@mailm1ph.message.cmbchina.com>" // ["toaddress"]=> // string(43) "=?utf-8?B?MjYwMDgzMzA0?= <260083304@qq.com>" // ["to"]=> // array(1) { // [0]=> // object(stdClass)#3 (3) { // ["personal"]=> // string(24) "=?utf-8?B?MjYwMDgzMzA0?=" // ["mailbox"]=> // string(9) "260083304" // ["host"]=> // string(6) "qq.com" // } // } // ["fromaddress"]=> // string(69) "=?utf-8?B?5oub5ZWG6ZO26KGM5L+h55So5Y2h?= <ccsvc@message.cmbchina.com>" // ["from"]=> // array(1) { // [0]=> // object(stdClass)#4 (3) { // ["personal"]=> // string(40) "=?utf-8?B?5oub5ZWG6ZO26KGM5L+h55So5Y2h?=" // ["mailbox"]=> // string(5) "ccsvc" // ["host"]=> // string(20) "message.cmbchina.com" // } // } // ["reply_toaddress"]=> // string(69) "=?utf-8?B?5oub5ZWG6ZO26KGM5L+h55So5Y2h?= <ccsvc@message.cmbchina.com>" // ["reply_to"]=> // array(1) { // [0]=> // object(stdClass)#5 (3) { // ["personal"]=> // string(40) "=?utf-8?B?5oub5ZWG6ZO26KGM5L+h55So5Y2h?=" // ["mailbox"]=> // string(5) "ccsvc" // ["host"]=> // string(20) "message.cmbchina.com" // } // } // ["senderaddress"]=> // string(69) "=?utf-8?B?5oub5ZWG6ZO26KGM5L+h55So5Y2h?= <ccsvc@message.cmbchina.com>" // ["sender"]=> // array(1) { // [0]=> // object(stdClass)#6 (3) { // ["personal"]=> // string(40) "=?utf-8?B?5oub5ZWG6ZO26KGM5L+h55So5Y2h?=" // ["mailbox"]=> // string(5) "ccsvc" // ["host"]=> // string(20) "message.cmbchina.com" // } // } // ["Recent"]=> // string(1) " " // ["Unseen"]=> // string(1) "U" // ["Flagged"]=> // string(1) " " // ["Answered"]=> // string(1) " " // ["Deleted"]=> // string(1) " " // ["Draft"]=> // string(1) " " // ["Msgno"]=> // string(4) "9602" // ["MailDate"]=> // string(26) " 2-Jul-2024 15:10:55 +0800" // ["Size"]=> // string(5) "45441" // ["udate"]=> // int(1719904255) //} ``` </details> <details> <summary>imap_fetchheader 返回單個字符串的 key: value 信息 </summary> ``` $imap_fetchheader = imap_fetchheader($inbox, 1,); string(1106) "Received: from mail.easyrote.com (unknown [219.232.246.83]) by newmx20.qq.com (NewMx) with SMTP id for <260083304@qq.com>; Fri, 10 Oct 2014 09:34:00 +0800 X-QQ-SSF: 00500000000000601x900001020052x Received: from 127.0.0.1 (unknown [219.232.246.84]) by mail.easyrote.com (Postfix - by easyrote.com) with ESMTPA id E14633670647 for <260083304@qq.com>; Fri, 10 Oct 2014 09:33:56 +0800 (CST) Date: Fri, 10 Oct 2014 09:33:54 +0800 To: =?UTF-8?B?5pmD5pmD5oKg5oKgdGltZQ==?= <260083304@qq.com> From: =?UTF-8?B?5piT5ZGX572R?= <noreply@yibei.com> Subject: =?UTF-8?B?5qyi6L+O5Yqg5YWl5piT5ZGX572R44CC?= Message-ID: <398f3bc0ff6f963daf09475b9878474d@127.0.0.1> X-Priority: 3 X-Mailer: PHPMailer 5.0.0 (phpmailer.codeworxtech.com) MIME-Version: 1.0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable " ``` </details> <details> <summary>imap_fetch_overview 可以獲取多個郵箱的對象數組信息,適用于快速郵件列表獲取</summary> ``` $imap_fetch_overview = imap_fetch_overview($inbox, $num-1); var_dump($imap_fetch_overview); //array(1) { // [0]=> // object(stdClass)#2 (13) { // ["subject"]=> // string(28) "=?utf-8?B?VGVzdCBtZXNzYWdl?=" // ["from"]=> // string(36) "=?utf-8?B?c2VuZGVy?= <sender@qq.com>" // ["to"]=> // string(43) "=?utf-8?B?MjYwMDgzMzA0?= <260083304@qq.com>" // ["size"]=> // int(135) // ["uid"]=> // int(10585) // ["msgno"]=> // int(9600) // ["recent"]=> // int(0) // ["flagged"]=> // int(0) // ["answered"]=> // int(0) // ["deleted"]=> // int(0) // ["seen"]=> // int(1) // ["draft"]=> // int(0) // ["udate"]=> // int(1719900791) // } //} ``` </details> ### imap_delete/imap_expunge 刪除郵箱 ``` // 刪除最新一封郵箱 $num = imap_num_msg($inbox); // 獲取郵箱總數 imap_delete($inbox,$num); imap_expunge($inbox); ``` ### imap_search 參數說明 ``` ALL:匹配所有消息。 ANSWERED:匹配已標記為已回答的消息。 BCC "string":匹配在密件抄送(Bcc)字段中包含“string”的消息。 BEFORE "date":匹配日期在“date”之前的消息。 BODY "string":匹配郵件正文中包含“string”的消息。 CC "string":匹配在抄送(Cc)字段中包含“string”的消息。 DELETED:匹配已刪除的消息。 FLAGGED:匹配標記為重要或緊急(\FLAGGED)的消息。 FROM "string":匹配發件人字段中包含“string”的消息。 KEYWORD "string":匹配包含關鍵詞“string”的消息。 NEW:匹配新消息(未讀消息,\RECENT標志和未設置\SEEN標志)。 OLD:匹配舊消息(已讀消息或非最近的消息)。 ON "date":匹配日期為“date”的消息。 RECENT:匹配最近的消息(具有\RECENT標志)。 SEEN:匹配已讀消息(設置了\SEEN標志)。 SINCE "date":匹配日期在“date”之后的消息。 SUBJECT "string":匹配主題中包含“string”的消息。 TEXT "string":匹配消息中任意部分包含“string”的消息。 TO "string":匹配收件人字段中包含“string”的消息。 UNANSWERED:匹配未標記為已回答的消息。 UNDELETED:匹配未刪除的消息。 UNFLAGGED:匹配未標記為重要或緊急的消息。 UNKEYWORD "string":匹配不包含關鍵詞“string”的消息。 UNSEEN:匹配未讀消息(未設置\SEEN標志)。 ``` ### imap_mime_header_decode ``` $text = "=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld@example.com>"; $elements = imap_mime_header_decode($text); for ($i=0; $i<count($elements); $i++) { echo "Charset: {$elements[$i]->charset}\n"; echo "Text: {$elements[$i]->text}\n\n"; } ``` ### 批量獲取頭信息,并獲取body ``` <?php // IMAP 服務器配置 $hostname = '{imap.qq.com:993/ssl}INBOX'; $username = '2600xxx304@qq.com'; $password = 'gxxxhinbibb'; // 打開 IMAP 連接 $inbox = imap_open($hostname, $username, $password,OP_READONLY) or die('Cannot connect to mail server: ' . imap_last_error()); $currentDate = new \DateTime(); $currentDate->modify("-1 days"); $opt = "SINCE {$currentDate->format('d-M-Y')}"; $arr = imap_search($inbox, $opt,SE_UID); // 返回uid 數組 [1,2,3,...] $emailHeads = imap_fetch_overview($inbox, implode(",",$arr), FT_UID); // 返回郵箱元數據 數組 foreach ($emailHeads as $emailHead){ // 解析頭文件 $email['subject']=imap_mime_header_decode($emailHead->subject)[0]->text; $email['from']=imap_mime_header_decode($emailHead->from)[1]->text; $email['from_name']=imap_mime_header_decode($emailHead->from)[0]->text; $email['to']=imap_mime_header_decode($emailHead->to)[1]->text; $email['size']=$emailHead->size; $email['flagged']=$emailHead->flagged; $email['answered']=$emailHead->answered; $email['unread']=$emailHead->seen; $email['deleted']=$emailHead->deleted; $email['udate']=(int)$emailHead->udate; $email['date']=(int)strtotime($emailHead->date); // imap_fetch_overview 可能沒有 $email['uid']=$emailHead->uid; // 獲取body,實際中,可點擊后獲取 $structure = imap_fetchstructure($inbox, 100); $imap_body = imap_fetchbody($inbox, 100,2); $body=''; switch ($structure->encoding) { case 3:$body= imap_base64($imap_body);break; case 4: $body= imap_qprint($imap_body);break; default: $body= $imap_body; } // 展示 file_put_contents("1.html",$body); } // 關閉 IMAP 連接 imap_close($inbox); ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看