imap_fetchheader

(PHP 4, PHP 5, PHP 7, PHP 8)

imap_fetchheaderRetorna o cabeçalho de uma mensagem

Descrição

imap_fetchheader(IMAP\Connection $imap, int $message_num, int $flags = 0): string|false

Esta função causa uma busca do cabeçalho completo e não filtrado no formato » RFC2822 da mensagem especificada.

Parâmetros

imap

Uma instância de IMAP\Connection.

message_num

O número da mensagem

flags

Os possíveis valores para flags são:

  • FT_UID - O argumento message_num é um UID
  • FT_INTERNAL - A string de retorno está no formato "interno", sem nenhuma tentativa de canonizar para novas linhas CRLF
  • FT_PREFETCHTEXT - O RFC822.TEXT deve ser pré-buscado ao mesmo tempo. Isso evita um RTT extra em uma conexão IMAP se um texto de mensagem completo for desejado (por exemplo, em uma operação "salvar em arquivo local")

Valor Retornado

Retorna o cabeçalho da mensagem especificada como uma sequência de texto, ou false em caso de falha.

Registro de Alterações

Versão Descrição
8.1.0 O parâmetro imap agora espera uma instância de IMAP\Connection; anteriormente, um resource imap válido era esperado.

Veja Também

adicione uma nota

Notas Enviadas por Usuários (em inglês) 2 notes

up
7
rgagnon24 dot nospam at gmail dot com
14 years ago
Interesting that imap_headerinfo() does not allow a UID for the $msg_number field like all other fetching functions seem to allow.

If you want to use a UID to fetch the headers, use this two-step process:

<?php
/*
* assumes $mbox is your stream, and $uid is set
* properly. Proper error checking is up to you.
*/
$hText = imap_fetchbody($mbox, $uid, '0', FT_UID);
$headers = imap_rfc822_parse_headers($hText);
?>

The result is the same as the output of imap_headerinfo(), but you get to use the UID.
up
3
Jille at nomorecrap dot quis dot cx
17 years ago
<?PHP
$headers
=imap_fetchheader($imap, $msgid);
preg_match_all('/([^: ]+): (.+?(?:\r\n\s(?:.+?))*)\r\n/m', $headers, $matches);
?>

Works quite well for splitting headers,
$matches will contain 3 arrays:
$matches[0] are the full-lines (To: Jille@devnull.quis.cx\r\n)
$matches[1] will be the header (To)
$matches[2] will be the value (Jille@devnull.quis.cx)

In multi-line values the 'multilining is not stripped!'
this could be achieved with something like:
<?PHP
preg_replace
('/\r\n\s+/m', '', $matches[2]);
?>
To Top