从gmail-api获取发件人电子邮件 [英] Get sender email from gmail-api

查看:116
本文介绍了从gmail-api获取发件人电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gmail-api,但无法获取发件人的电子邮件.我说的是电子邮件的完整"格式.我认为发件人的电子邮件实际上是使用gmail网络界面在发件人"字段中写的电子邮件. 这种完整格式的标头通常包含"X-Original-Authentication-Results"之类的内容,通常我可以从中检索作为发件人电子邮件的smtp.mail值,但在其他电子邮件中找不到此标头.

I am using the gmail-api and having trouble getting the email of the sender. I am talking about the "full" format of the email. I consider the email of the sender to be the one that is actually written in the "From" field using the web interface of gmail. The headers of this full format usually include stuff like "X-Original-Authentication-Results" from which normally I can retrieve the smtp.mail value which is the sender's email but there are other emails where this header cannot be found.

到目前为止,这是我的代码:

This is my code so far:

if ("X-Original-Authentication-Results" == $header["name"]) {
        $value = $header["value"];
        preg_match("/smtp.mail=(.*)/", $value, $emailFound);
        $parsedEmail = $emailFound[1];
}

这是一些标题的典型格式:

and here is a typical format of some headers:

[headers] => Array
                    (
                        [0] => Array
                            (
                                [name] => Delivered-To
                                [value] => randomemail@gmail.com
                            )

                        [1] => Array
                            (
                                [name] => Received
                                [value] => ................
                            )

                        [2] => Array
                            (
                                [name] => X-Received
                                [value] => ................
                            )

                        [3] => Array
                            (
                                [name] => Return-Path
                                [value] => 
                            )

                        [4] => Array
                            (
                                [name] => Received
                                [value] => ................
                            )

                        [5] => Array
                            (
                                [name] => Received-SPF
                                [value] => ................
                            )

                        [6] => Array
                            (
                                [name] => Authentication-Results
                                [value] => ................
                            )
........

那么有没有可靠的方法来获取发件人的正确电子邮件? 预先谢谢你!

So is there a solid way to get the correct email of the sender? Thank you in advance!

推荐答案

在headers []数组中循环,然后查找带有'name'="From"的名称(或您感兴趣的任何标题名称) ).请注意,可能有多个具有该名称的标头.通常会存在一些标准标头(收件人",发件人",主题"),但我不认为这是RFC规定的.

Loop through the headers[] array and look for the one with the 'name' = "From" (or whatever the header name is you're interested in). Note there may be multiple headers with that name. There are some standard headers that will usually exist (To, From, Subject) but I don't believe that's mandated by the RFC.

这篇关于从gmail-api获取发件人电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆