title: Get sender email from gmail-api
body: <p>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.</p>
  
  <p>This is my code so far:</p>
  
  <pre><code>if ("X-Original-Authentication-Results" == $header["name"]) {
          $value = $header["value"];
          preg_match("/smtp.mail=(.*)/", $value, $emailFound);
          $parsedEmail = $emailFound[1];
  }
  </code></pre>
  
  <p>and here is a typical format of some headers:</p>
  
  <pre><code>[headers] =&gt; Array
                      (
                          [0] =&gt; Array
                              (
                                  [name] =&gt; Delivered-To
                                  [value] =&gt; randomemail@gmail.com
                              )
  
                          [1] =&gt; Array
                              (
                                  [name] =&gt; Received
                                  [value] =&gt; ................
                              )
  
                          [2] =&gt; Array
                              (
                                  [name] =&gt; X-Received
                                  [value] =&gt; ................
                              )
  
                          [3] =&gt; Array
                              (
                                  [name] =&gt; Return-Path
                                  [value] =&gt; 
                              )
  
                          [4] =&gt; Array
                              (
                                  [name] =&gt; Received
                                  [value] =&gt; ................
                              )
  
                          [5] =&gt; Array
                              (
                                  [name] =&gt; Received-SPF
                                  [value] =&gt; ................
                              )
  
                          [6] =&gt; Array
                              (
                                  [name] =&gt; Authentication-Results
                                  [value] =&gt; ................
                              )
  ........
  </code></pre>
  
  <p>So is there a solid way to get the correct email of the sender?
  Thank you in advance!</p>