1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Rep Power

    Question Getting addresses of emails using Imap

    Hi all,

    Does anyone knows how I could get all the addresses of an email using PHP imap?

    I followed the example given in the usual PHP website. At the end of the page, you can see the following example:
    PHP Code:
    $header imap_header($mbox$message_id);
    $from $header->from;
    foreach (
    $from as $id => $object) {
    $fromname $object->personal;
    $fromaddress $object->mailbox "@" $object->host;

    I've change the $header->from with a $header->to to get the "To" addresses. Apparently, the imap_header function retrieves an array of address objects. So this code loops over the address objects to get all the addresses, fine.

    The problem is that the $header->to property returns only one address object, even with email containing several "To" addresses (that I can check using a webmail interface).

    Do you know how I could get the actual array of addresses?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Rep Power
    The object should be an array of 'to' addresses just like 'from'. I suggest you do the following to see what is really there:
    PHP Code:
    echo "<pre>";
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo