2013-04-18 42 views
1

我使用php imap函數imap_header來提取完整​​標題,並使用imap_fetch_overview來提取原始標題。這兩個函數分別爲我提供了stdClass對象和數組。從imap標題檢索電子郵件地址

我希望在進一步處理之前始終保持清潔。有時,一個從或向可以包含一些像這樣的事情, Test user <[email protected]>

而且目前我從我只看到Test User並沒有電子郵件地址,直到我用螢火蟲。

如何從這些對象數組中獲取[email protected]

這是結果我從imap_fetch_overview

Array 
    (
    [0] => stdClass Object 
    (
     [subject] => Testing 
     [from] => Test User 
     [to] => [email protected] 
     [date] => Wed, 17 Apr 2013 18:43:46 +0530 
     [message_id] => <[email protected]> 
     [size] => 3443 
     [uid] => 1234 
     [msgno] => 123 
     [recent] => 0 
     [flagged] => 0 
     [answered] => 0 
     [deleted] => 0 
     [seen] => 0 
     [draft] => 0 
     [udate] => 1366204439 
    ) 

) 

那裏是一個隱藏<[email protected]>旁邊的測試用戶。我如何提取該電子郵件地址?

同樣這是我從imap_header

stdClass Object 
    (
    [date] => Wed, 17 Apr 2013 18:43:46 +0530 
    [Date] => Wed, 17 Apr 2013 18:43:46 +0530 
    [subject] => Test 
    [Subject] => Test 
    [message_id] => <[email protected]> 
    [toaddress] => [email protected] 
    [to] => Array 
    (
     [0] => stdClass Object 
      (
       [mailbox] => testuser 
       [host] => test.com 
      ) 

    ) 

    [fromaddress] => Test User 
    [from] => Array 
    (
     [0] => stdClass Object 
      (
       [personal] => Test User 
       [mailbox] => test 
       [host] => test.com 
      ) 

    ) 

    [reply_toaddress] => Test User 
    [reply_to] => Array 
    (
     [0] => stdClass Object 
      (
       [personal] => Test User 
       [mailbox] => test 
       [host] => test.com 
      ) 

    ) 

    [senderaddress] => Test User 
    [sender] => Array 
    (
     [0] => stdClass Object 
      (
       [personal] => Test User 
       [mailbox] => test 
       [host] => test.com 
      ) 

    ) 

    [Recent] => 
    [Unseen] => U 
    [Flagged] => 
    [Answered] => 
    [Deleted] => 
    [Draft] => 
    [Msgno] => 123 
    [MailDate] => 17-Apr-2013 13:13:59 +0000 
    [Size] => 3443 
    [udate] => 1366204439 
) 

一個preg_match得到將是顯而易見的答案,但只是不能似乎想出如何從那裏的電子郵件地址未在瀏覽器中看到的位執行,但在用螢火蟲檢查時存在。任何幫助表示讚賞。

謝謝。

回答

0

如果STD對象的數組的名稱爲$常用3

$arr[0]->to 

回報你想要什麼。

在第二種情況下

$ stdObject < - 由第二函數返回的對象

foreach($stdObject->to as $to) 
{ 
echo $to->mailbox; 
echo $to->host; 
} 
+0

在第一種情況下'$ arr [0] - > to'給我測試用戶。不給我電子郵件地址。但通過螢火蟲檢查後,我可以看到它將我的電子郵件地址視爲標籤。 '<[email protected]>'。任何想法爲什麼這樣做,應該做些什麼來糾正它? – ivn03

2

你可以走一步與imap_rfc822_parse_adrlist()Docs

$toAddresses = imap_rfc822_parse_adrlist('Test user <[email protected]>', 'localhost'); 

print_r($toAddresses); 

Array 
(
    [0] => stdClass Object 
     (
      [mailbox] => test 
      [host] => test.com 
      [personal] => Test user 
     ) 

) 
+0

問題是我沒有在FROM中看到我的電子郵件地址,直到我使用螢火蟲。它以'<[email protected]>'標籤的形式出現。因此'imap_rfc822_parse_adrlist()不起作用。我已經從我的完整標題中獲得了該陣列表單(郵箱,主機,個人),但是如何獲取在瀏覽器 – ivn03

+2

中未使用的電子郵件地址,而不是使用view-source而不是螢火蟲。 fire-bug並且你的瀏覽器把它當作HTML標籤(因爲它以'<'開頭)。或者以「Content-Type:text/plain」的形式提供輸出,但我想你的調試只是想查看源代碼。 – hakre

相關問題