在 php imap 中获取 X-Mailer 属性
如何在 php imap lib 中获取 X-Mailer 属性?
我找不到属性 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
"
how I can get X-Mailer attribute in php imap lib ?
I can't find any fetch function for attribute 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);
output I am getting is
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
"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
方法:
示例:
Method:
Example:
免责声明:以下内容使用其他人的代码,但我相信它会对其他人有所帮助(在我的情况下,我需要这个,因为 ddeboer /imap 库不支持标头)。
Peter的解决方案很棒,但我必须使用fred727 的正则表达式以避免获取带有换行符的键。
因为一封电子邮件可以多次具有给定的标头,所以我必须使用 允许重复键的
array_combine()
变体。这是解析 RFC822 headers-part 字符串的最终代码(获取此类部分超出了范围):
效果很好。以下是使用相同
$string
的示例(添加了Received
标头):输出:
Disclaimer: The following uses code from other, but I am sure it would help others (in my case I needed this because ddeboer/imap library does not support headers).
Peter's solution is great but I had to use fred727's regular expression to avoid getting keys with newline characters.
Because an e-mail can have a given header multiple times, I had to use an
array_combine()
variant that allows duplicate keys.Here is the final code to parse a RFC822 headers-part string (fetching such part is out of scope):
Which works great. Here is an example using the same
$string
(with addedReceived
header):Which outputs: