php imap 从电子邮件地址获取
如何使用 imap_open 从电子邮件中检索电子邮件地址?
如果发件人姓名已知,并且使用“from”参数,我将获得发件人姓名而不是电子邮件地址。
How do I retrieve the email address from an email with imap_open?
If the sender name is known I get the sender name instead of the email address if I use the 'from' parameter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我也与此作斗争,但以下有效:
我使用了 imap_fetch_overview() 但 imap_header() 为我提供了我需要的所有信息。
I battled with this as well but the following works:
I had used imap_fetch_overview() but the imap_header() gave me all the information I needed.
最坏的情况,您可以自己解析标头,如下所示:
$matches will contains 3 arrays:
Get this from: http://www.php.net/manual/en/function.imap-fetchheader.php#82339
Worst case, you can parse the headers yourself with something like:
$matches will contain 3 arrays:
Got this from: http://www.php.net/manual/en/function.imap-fetchheader.php#82339
和你有同样的问题......必须把它拼凑在一起,不知道为什么它如此奇葩。
此处未经测试的示例:
Had same issue as you....had to piece it together, don't know why it's such gonzoware.
Untested example here:
imap_fetch_overview
可能就是您正在寻找的:http://www.php.net/manual/en/function.imap-fetch-overview.php可以在此处找到使用示例:http://davidwalsh.name/gmail-php-imap,特别是
echo $overview[0]->from;
这个函数很简单,但是有局限性。更详尽的版本位于
imap_headerinfo
(http: //www.php.net/manual/en/function.imap-headerinfo.php ),它可以返回所有标头数据的详细数组。imap_fetch_overview
could be what you're looking for: http://www.php.net/manual/en/function.imap-fetch-overview.phpAn example of use can be found here: http://davidwalsh.name/gmail-php-imap, specifically
echo $overview[0]->from;
This function is simple, but has limitations. A more exhaustive version is in
imap_headerinfo
( http://www.php.net/manual/en/function.imap-headerinfo.php ) which can return detailed arrays of all header data.遇到麻烦,直到我发现 $header 是 stdClass 对象的数组。以下两行有效:
Had trouble until I spotted that the $header is an array of stdClass Objects. The following 2 lines worked:
带有在线示例的完整工作代码
使用 PHP 和 IMAP 从收件箱中提取电子邮件地址列表
inbox-using-php-and-imap
我认为您所需要的只是复制脚本。
我也在这里发布了代码的两个核心功能(感谢 Eineki 的评论)
Full working code with an online example
Extract email addresses list from inbox using PHP and IMAP
inbox-using-php-and-imap
I think all you need is just to copy the script.
I am publishing two core functions of the code here as well (thanks to Eineki's comment)