note 81635 added to function.imap-fetchheader
| From: | onofabio at gmail dot com | Date: | Fri, 07 Mar 2008 11:18:24 +0000 |
| Subject: | note 81635 added to function.imap-fetchheader | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136815@lists.php.net to get a copy of this message | ||
This function ignore that some header value have multiple lines...
<?php
// connecting to imap mailserver
$connection = @imap_open("{localhost:143/imap}INBOX", "your_username",
"your_password");
// get imap_fetch header and put single lines into array
$header = explode("\n", imap_fetchheader($connection, 1));
// 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];
}
}
}
// now are all contained additional headers in array $head
?>
I write this simple function....
$mbox = imap_open("{localhost:143/imap}INBOX", "your_username",
"your_password");
$mid=1 // Message id
// Get headers
$header = imap_fetchheader($mbox, $mid);
// Split on \n
$h_array=split("\n",$header);
foreach ( $h_array as $h ) {
// Check if row start with a char
if ( preg_match("/^[A-Z]/i", $h )) {
$tmp = split(":",$h);
$header_name = $tmp[0];
$header_value = $tmp[1];
$headers[$header_name] = $header_value;
} else {
// Append row to previous field
$headers[$header_name] = $header_value . $h;
}
}
----
Server IP: 80.241.173.254
Probable Submitter: 83.211.208.114
----
Manual Page -- http://www.php.net/manual/en/function.imap-fetchheader.php
Edit -- https://master.php.net/note/edit/81635
Del: integrated -- https://master.php.net/note/delete/81635/integrated
Del: useless -- https://master.php.net/note/delete/81635/useless
Del: bad code -- https://master.php.net/note/delete/81635/bad+code
Del: spam -- https://master.php.net/note/delete/81635/spam
Del: non-english -- https://master.php.net/note/delete/81635/non-english
Del: in docs -- https://master.php.net/note/delete/81635/in+docs
Del: other reasons-- https://master.php.net/note/delete/81635
Reject -- https://master.php.net/note/reject/81635
Search -- https://master.php.net/manage/user-notes.php