receivemail是乙個老外寫利用pop3協議讀取郵件的類,但是不支援中文,筆者找了不少資料,整合了許多網友改造的receivemail類,支援多種郵件編碼。
receivemail類:
class
receivemail
&uxzo1mwhtvzzoq-/beifen';
function
__construct
($username, $password, $emailaddress, $mailserver = 'localhost', $servertype = 'pop', $port = '110', $ssl = false)
inbox';
} else inbox';
}$this->server = $strconnect;
$this->username = $username;
$this->password = $password;
$this->email = $emailaddress;
}function
connect
()
}function
testconnect
() $this->close_mailbox();
return
true;
}function
listmessages
($page = 1, $per_page = 25, $sort = null)
else
$result = imap_fetch_overview($this->marubox, implode($msgs, ','), 0);
if (false === is_array($result))
return
false;
foreach ($result
as$k => $r)
//sorting!
if (true === is_array($sorted))
$result = array();
foreach ($msgs
as$msgno)
}$return = array('res' => $result,
'start' => $start,
'limit' => $limit,
'sorting' => array('by' => $sort[0], 'direction' => $sort[1]),
'total' => imap_num_msg($this->marubox));
$return['pages'] = ceil($return['total'] / $per_page);
return
$return;
}function
getheaders
($mid)
return
$mail_details;
}function
get_mime_type
(&$structure)
return
"text/plain";
}function
get_part
($stream, $msg_number, $mime_type, $structure = false, $part_number = false)
if ($structure)
$text = imap_fetchbody($stream, $msg_number, $part_number);
if ($structure->encoding == 3) else
if ($structure->encoding == 4) else
}if ($structure->type == 1) /* multipart */
$data = $this->get_part($stream, $msg_number, $mime_type, $sub_structure, $prefix . ($index + 1));
if ($data) }}
}return
false;
}function
gettotalmails
() ", '*');
return count($headers);
}function
getattach
($mid, $path)
$struckture = imap_fetchstructure($this->marubox, $mid);
$ar = "";
if ($struckture->parts)
// 檔名轉換
$name = explode('.', $name);
$firs_name = urlencode($name[0]);
$filename = $firs_name . '.' . $name[1];
$fp = fopen($path . $filename, "w"); //fopen 中文檔名
fwrite($fp, $message);
fclose($fp);
$ar = $ar . $filename . ",";}}
}$ar = substr($ar, 0, (strlen($ar) - 1));
return
$ar;
}function
removeeamil
($mid)
function
getbody
($mid)
$body = $this->get_part($this->marubox, $mid, "text/html");
if ($body == "")
if ($body == "")
return
$this->_iconv_utf8($body);
}function
deletemails
($mid)
function
close_mailbox
()
function
_imap_utf8
($text)
if (strtolower(substr($match[1], 0, 2)) == 'ut')
}return
$text;
}return
$this->_iconv_utf8($text);
}function
_iconv_utf8
($text)
else
}}
使用方法:
$obj
=new receivemail(
$address,
$password,
$address,
$server,
'pop3',
$port,
$ssl);
//連線伺服器
$obj
->connect();
//獲取郵件總數
$obj
->gettotalmails();
//分頁獲取
$mails
=$obj
->listmessages($page,$perpage,[
'date','desc']);
//關閉連線
$obj->close_mailbox();
php 使用vscode除錯php
安裝外掛程式php debug。找到xampp安裝目錄下的readme en.txt檔案,檢視php的具體版本php 5.6.30 vc11 x86 32bit thread safe pear。返回上級目錄,即c xampp php,找到php.ini,按照下面的列表配置,配置完成後重啟apach...
php陣列使用
1,把陣列轉成字串用逗號分開 implode array 2,多個陣列比較,去除相同的元素,返回不同的元素 array diff array1,array2,例如 a array 1,2,3,4,5,6 b array 2,3 c array 4,5 則 d array diff a,b,c 值為 ...
php基本使用
可以出現在任何位置 php檔案需要執行在伺服器環境,在瀏覽器中輸入localhost ajax 01.phpphp語句要求末尾加分號 echo 以 開頭,後面變數名稱 變數命名規則 與js相同 a 10 b hello world c true echo a.10 echo b.hello worl...