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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.