2014-03-27 240 views
0

對,所以,即時通訊工作的系統,通過電子郵件收件箱,並獲取每個電子郵件的標題,並與他們做的東西。PHP IMAP:比較電子郵件CC與電子郵件存儲在變量

我試圖比較電子郵件CC與變量中設置的電子郵件。 問題是,當我回聲出CC,它示出了如

[email protected]

雙qoutes輪它。 所以我嘗試此代碼:

$hostemail = '[email protected]'; $hostemail2 = '"'.$hostemail.'"'; 

其中$ hostemail2是呼應了用雙引號圓它,並試圖通過

$header = imap_header($imap, $message); //Get headers 
$cc = $header->ccaddress; //get the ccaddress header 
if($cc == $hostemail2) { echo 'Well done'; } //if cc equals variable set before 
else { echo 'Not gonna happen'; } //otherwise, yaknow 

比較一直給我Not gonna happen

回答

0

而不是使用$header->ccaddress的,它是更好地使用CC陣列

$cc = "{$header->cc[0]->mailbox}@{$header->cc[0]->host}";那裏還能有它周圍沒有doubleqotes來獲取數據,然後你可以做if聲明

if ($cc2 == $hostemail) { echo "Hi";}

欲瞭解更多信息,請訪問PHP: imap_headerinfo