php - Get "From" and "To" addresses with Gmail API -


i use gmail api retrieving messages gmail account , storing them in db. want store to/from email addresses each message.

each message contains headers array , within array there 2 fields "from" , "to". contain contact name, not pure email address.

so right parse them this:

if ($header->name === 'from') {     preg_match_all("/[\._a-za-z0-9-]+@[\._a-za-z0-9-]+/i", $header->value, $matches);     $from = $matches[0][0]; } 

but way to/from adresses? manually parsing headers?

yes. user.messages includes from/to in standard rfc 2822 headers.

you should avoid using regex parse email addresses though. complex , can contain character. see regex example of compliant version like.


Comments

Popular posts from this blog

android - How to save instance state of selected radiobutton on menu -

python 3 IndexError: list index out of range -

IF statement in MySQL trigger -