Jump to content

[SOLVED] PHP IMAP and X-Headers


nljeffrey

Recommended Posts

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/67415-solved-php-imap-and-x-headers/
Share on other sites

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>";
}
}

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.