php imap来自电子邮件地址

Fre*_*nck 14 php email imap

如何从imap_open的电子邮件中检索电子邮件地址?

如果我知道发件人姓名,我会使用'from'参数获取发件人姓名而不是电子邮件地址.

代码:http://gist.github.com/514207

dlo*_*dlo 33

$header = imap_headerinfo($imap_conn, $msgnum);
$fromaddr = $header->from[0]->mailbox . "@" . $header->from[0]->host;
Run Code Online (Sandbox Code Playgroud)


Mat*_*son 3

最坏的情况,您可以使用以下内容自行解析标头:

<?php
$headers=imap_fetchheader($imap, $msgid);
preg_match_all('/([^: ]+): (.+?(?:\r\n\s(?:.+?))*)\r\n/m', $headers, $matches);
?>
Run Code Online (Sandbox Code Playgroud)

$matches 将包含 3 个数组:

$matches[0] are the full-lines (such as "To: user@user.com\r\n")
$matches[1] will be the header (such as "To")
$matches[2] will be the value (user@user.com)
Run Code Online (Sandbox Code Playgroud)

来自:http://www.php.net/manual/en/function.imap-fetchheader.php#82339