Получение атрибута X-Mailer в php imap
Как я могу получить атрибут X-Mailer в php imap lib?
Я не могу найти функцию выборки для атрибута http://php.net/manual/en/function.imap-fetchheader.php
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
$header = imap_fetchheader($inbox, 1);
var_dump($header);
/* close the connection */
imap_close($inbox);
Вывод, который я получаю, это
string(405) "MIME-Version: 1.0
Received: by 10.42.228.195; Wed, 16 Feb 2011 21:18:06 -0800 (PST)
Date: Wed, 16 Feb 2011 21:18:06 -0800
Message-ID: <[email protected]>
Subject: Get Gmail on your mobile phone
From: Gmail Team <[email protected]>
To: test case2 <[email protected]>
Content-Type: multipart/alternative; boundary=20cf302234f1c34163049c73853c
"
2
Author: Vivek Goel, 2011-04-12
1 answers
Способ:
- Извлекать заголовки с помощью imap_fetchheader()
- Извлеките поле X-Mailer из заголовков
- Извлеките значение из поля
Пример:
$inbox = imap_open($hostname,$username,$password);
if (!$inbox) {
echo('Cannot connect to Gmail: ' . imap_last_error());
exit;
}
$header_string = imap_fetchheader($inbox, 1);
preg_match_all('/([^: ]+): (.+?(?:\r\n\s(?:.+?))*)\r\n/m',
$header_string, $matches);
$headers = array_combine($matches[1], $matches[2]);
$xmailer = $headers['X-Mailer'];
imap_close($inbox);
8
Author: Peter Lindqvist, 2011-04-12 07:37:42