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

    Join Date
    Jun 2010
    Posts
    191
    Rep Power
    44

    IMAP sender information using custom script


    I'm using the following script to pull attachments out of an email account via IMAP:

    https://gist.github.com/hakre/2363305

    Here is my implementation, taken from a blog post that referenced using the above script to accomplish what I was wanting:

    PHP Code:
    $inbox = new IMAPMailbox($hostname$username$password);
    $emails $inbox->search('ALL');
    if (
    $emails) {
        
    rsort($emails);    
        foreach (
    $emails as $email) {                
            foreach (
    $email->getAttachments() as $attachment) {
                
    $file_ext strtolower($attachment->getExtension());
                
    $newname $upload_dir."img_".uniqid().".".$file_ext;                        
                
    file_put_contents($newname$attachment);
            }        
        } 
    I want to extend this a bit by sending an automatic reply to the original sender letting them know that their attachment has been received and processed. However, since this tool uses custom classes to make the imap connection, I am unsure how to tap into the appropriate imap stream in order to get the "sender" address.

    If I was using imap_open, I think I could get it based on what I've read online. But instead, I'm using hakre's "new IMAPMailbox($hostname, $username, $password);" method, so things like imap_headers() don't seem to work.

    I've spent all morning trying various things to pull this out, and it's obvious that I don't know enough about classes and constructs to be successful, so I thought I'd ask for an expert eye to take a look.

    Thanks in advance!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,232
    Rep Power
    593
    How you respond to the email is unrelated to how you obtain them. Simply respond using PHPMailer.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,920
    Rep Power
    1045
    Hi,

    IMAPMessage::fetchOverview() calls imap_fetch_overview(), which in turn yields the basic headers of the message.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    191
    Rep Power
    44
    Originally Posted by Jacques1
    Hi,

    IMAPMessage::fetchOverview() calls imap_fetch_overview(), which in turn yields the basic headers of the message.
    You're exactly right. Thank you so much, I was able to get the "from" field based on your nudge in the right direction.

    One more question, based on the output I'm receiving. Some of the values of the "from" field are shown as email addresses with '@' and others are only showing the users display name. Should I be using a different field to ensure I am replying to email addresses only?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,232
    Rep Power
    593
    Sorry for my irrelevant reply. I misunderstood what you were asking.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2010
    Posts
    191
    Rep Power
    44
    Originally Posted by BlackAce
    One more question, based on the output I'm receiving. Some of the values of the "from" field are shown as email addresses with '@' and others are only showing the users display name. Should I be using a different field to ensure I am replying to email addresses only?
    Just tested it, and it sends the reply to everyone, whether or not the "from" header is displaying an actual email address or not. Not sure why this is, but there must be some data that doesn't get returned on screen. Just wanted to follow-up should anyone stumble on this.

    Originally Posted by gw1500se
    Sorry for my irrelevant reply. I misunderstood what you were asking.
    No worries.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,232
    Rep Power
    593
    You should first check for a 'reply-to' header and use it if present. Otherwise use the 'from' header. However, none are guaranteed to be a valid address if the sender wants to obscure their real address.
    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