nljeffrey Posted August 31, 2007 Share Posted August 31, 2007 Hey All, I'm trying to parse incoming e-mail. The information I need is in the X-Header of an e-mail. I have the following code: $user = "Uid"; $pass = "Pw"; $imap = imap_open("{URL_TO_IMAP}INBOX", $user, $pass); if (!$imap) { print_r(imap_errors()); } $headers = @imap_headers($imap); if (!$headers) { echo 'Kan geen mail ontvangen'; exit(); } $numEmails = sizeof($headers); * EDIT * I think I need to use imap_fetchheader to retrieve all header info... for($i = 1; $i < $numEmails+1; $i++) { $mailHeader = @imap_headerinfo($imap, $i); print_r($mailHeader); } I see the message header, but I don't see any X Header? Where are the Xheaders; how can I retrieve them? Quote Link to comment https://forums.phpfreaks.com/topic/67415-solved-php-imap-and-x-headers/ Share on other sites More sharing options...
nljeffrey Posted August 31, 2007 Author Share Posted August 31, 2007 Ok I solved it...Here's my code: $ user = "UID"; $pass = "PW"; $imap = imap_open("{URL_TO_IMAP_SERVER}INBOX", $user, $pass); if (!$imap) { print_r(imap_errors()); } $headers = @imap_headers($imap); if (!$headers) { echo 'Couldn\'t get emails'; exit(); } $numEmails = sizeof($headers); echo "You have $numEmails mails in your mailbox<br><br>"; for($i = 1; $i < $numEmails+1; $i++) { // get imap_fetch header and put single lines into array $header = explode("\n", imap_fetchheader($imap, $i)); // browse array for additional headers if (is_array($header) && count($header)) { $head = array(); foreach($header as $line) { // is line with additional header? if (eregi("^X-", $line)) { // separate name and value eregi("^([^:]*): (.*)", $line, $arg); $head[$arg[1]] = $arg[2]; } } print 'Additional Headers:<br>'; print_r($head); print "<br><hr>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/67415-solved-php-imap-and-x-headers/#findComment-338439 Share on other sites More sharing options...
nljeffrey Posted September 3, 2007 Author Share Posted September 3, 2007 I've still got some problems The problem is that I miss a lot of header information... Content-Type: multipart/mixed; boundary="----=_Part_1234XXXXXX" Probably because of the mime / content-type in the header? How can I get the raw header from an e-mail message? Quote Link to comment https://forums.phpfreaks.com/topic/67415-solved-php-imap-and-x-headers/#findComment-340454 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.