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.
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.
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.
Had same issue as you....had to piece it together, don't know why it's such gonzoware.
Untested example here:
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
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.Had trouble until I spotted that the $header is an array of stdClass Objects. The following 2 lines worked:
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)