PHP使用imap_open實現(xiàn)讀取QQ郵箱
PHP代碼:
/**
PHP使用imap_open讀取QQ郵箱
imap_open 官方文檔:
https://www.php.net/function.imap_open
*/
function parse_mailstr($subject) {
$a = explode('?',$subject);
$n = count($a);
$a = $a[$n-2];
return base64_decode($a);
}
function recevie_email() {
// 騰訊 QQ 郵箱為例。
// 官方文檔:https://service.mail.qq.com/detail/0/339
$mailbox = '{imap.qq.com:993/imap/ssl}INBOX';
// 要讀取的郵箱
$user = 'youremail@qq.com';
// 郵箱密碼或授權碼。郵箱授權碼生成路徑如下:
// 進入 QQ 郵箱,依次進入【設置】-【賬號】-【POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服務-管理服務】-【安全設置】-【生成授權碼】
$password = '郵箱密碼或授權碼';
$inbox = imap_open($mailbox, $user, $password) or die(imap_last_error());
if ($inbox) {
$numMsg = imap_num_msg($inbox);
echo '<dt>共有 '.$numMsg.' 條未讀郵件</dt>';
for ($i = 1; $i <= $numMsg; ++$i) {
$hd = imap_headerinfo($inbox, $i);
$subject = parse_mailstr($hd->subject);
echo '<dd>';
echo "標 題:$subject <br />";
echo '發(fā)件人:'. $hd->from[0]->mailbox .'@'. $hd->from[0]->host .'<br />';
if (isset($hd->date)) {
$date = strtotime($hd->date);
$date = date('Y-m-d H:i:s',$date);
echo "時 間:$date <br />";
}
echo '</dd>';
}
imap_close($inbox);
}
}HTML代碼:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width,user-scalable=yes" />
<meta name="renderer" content="webkit" />
<style>
dd{
border-bottom: 1px solid #888;
padding-bottom: 10px;
padding-top: 10px;
}
</style>
<title>PHP使用imap_open讀取QQ郵箱</title>
</head>
<body>
<dl>
<?php recevie_email();?>
</dl>
</body>
</html>獲得郵箱授權碼方法:
進入 QQ 郵箱,依次進入【設置】-【賬號】-【POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服務-管理服務】-【安全設置】-【生成授權碼】。


到此這篇關于PHP使用imap_open實現(xiàn)讀取QQ郵箱的文章就介紹到這了,更多相關PHP讀取QQ郵箱內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
PHP實現(xiàn)駝峰樣式字符串(首字母大寫)轉換成下劃線樣式字符串的方法示例
這篇文章主要介紹了PHP實現(xiàn)駝峰樣式字符串(首字母大寫)轉換成下劃線樣式字符串的方法,涉及php正則替換相關操作技巧,需要的朋友可以參考下2017-08-08
PHP error_log()將錯誤信息寫入一個文件(定義和用法)
PHP error_log()定義和用法,帶有二個簡單小例子加函數(shù)解釋2013-10-10
PHP統(tǒng)計目錄下的文件總數(shù)及代碼行數(shù)(去除注釋及空行)
在開發(fā)的時候,為了統(tǒng)計開發(fā)出的代碼總行數(shù)及文件總數(shù),在沒有使用工具的時候,總是要去一個文件一個文件的查找,文件夾層次少還行,層次多的時候就累死人了2011-01-01
php實現(xiàn)通過soap調用.Net的WebService asmx文件
這篇文章主要介紹了php實現(xiàn)通過soap調用.Net的WebService asmx文件,結合實例形式分析了php使用soap實現(xiàn)WebService接口的調用技巧,需要的朋友可以參考下2017-02-02
highchart數(shù)據(jù)源縱軸json內的值必須是int(詳解)
下面小編就為大家?guī)硪黄猦ighchart數(shù)據(jù)源縱軸json內的值必須是int(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02

