我正在获取我INBOX
在 gmail 的电子邮件。我只想获取我将提供的那些 ID 的电子邮件。我不明白如何实现这一点。
当我尝试这样做时,imap_search
我没有取得任何成功,就像 -
$emails = imap_search($inbox,'rajeev@gmail.com');
但它给了我收件箱的所有电子邮件。
有什么建议可以实现我想要的吗?
我的代码是 -
function connect_mail(){
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = '***@gmail.com';
$password = 'password';
$inbox = imap_open($hostname,$username,$password) or die(t('Cannot connect to Gmail: ' . imap_last_error()));
$emails = imap_search($inbox,'UNREAD');
$Msgcount = count($emails);
for ($x = 1; $x <= $Msgcount; $x++)
{
$overview = imap_fetch_overview($inbox, $x);
$title = $overview[0]->subject;
$struct = imap_fetchstructure($inbox,$x);
$contentParts = count($struct->parts);
if ($contentParts >= 2) {
for ($i=2;$i<=$contentParts;$i++) {
$att[$i-2] = imap_bodystruct($inbox,$x,$i);
}
for ($k=0;$k<sizeof($att);$k++) {
if ($att[$k]->parameters[0]->value == "us-ascii" || $att[$k]->parameters[0]->value == "US-ASCII") {
if ($att[$k]->parameters[1]->value != "") {
$selectBoxDisplay[$k] = $att[$k]->parameters[1]->value;
}
}
elseif ($att[$k]->parameters[0]->value != "iso-8859-1" && $att[$k]->parameters[0]->value != "ISO-8859-1") {
$selectBoxDisplay[$k] = $att[$k]->parameters[0]->value;
}
}
}
if (sizeof($selectBoxDisplay) > 0) {
echo "<select name=\"attachments\" size=\"3\" class=\"tblContent\" onChange=\"handleFile(this.value)\" style=\"width:170;\">";
for ($j=0;$j<sizeof($selectBoxDisplay);$j++) {
$filename = $selectBoxDisplay[$j];
echo "\n<option value=\"$j\">". $selectBoxDisplay[$j] ."</option>";
}
echo "</select>";
}
$strFileName = $att[$file]->parameters[0]->value;
$strFileType = strrev(substr(strrev($filename),0,4));
$fileContent = imap_fetchbody($inbox, $x, $file+2);
$ContentType = "application/octet-stream";
list($file_first_name, $extension) = explode('. ', $filename);
if ($extension == ".jpg" || $extension == "jpeg" || $extension == ".JPG")
$ContentType = "image/jpeg";
if ($extension == ".doc")
$ContentType = "application/msword";
header ("Content-Type: $ContentType");
header ("Content-Disposition: attachment; filename=$strFileName; size=$fileSize;");
if (substr($ContentType,0,4) == "text") {
echo imap_qprint($fileContent);
}
else {
echo base64_decode($fileContent);
}
}
}