?
Solved

IMAP get entire message

Posted on 2012-04-09
3
Medium Priority
?
377 Views
Last Modified: 2012-04-11
Hi all,
Ive been struggling with this for a while, so hopefully someone can help.

This is a very simple script using PHP imap functions to read a mailbox. Is there a function I can use to get the entire source of the message (the same as I would see if I was viewing the source in outlook etc). So for a mime message I would get the entire thing, headers and everything?


<?php


    $imap = imap_open("{SERVER}", "email@domain.com", "password");
    $message_count = imap_num_msg($imap);



    for ($i = 1; $i <= $message_count; ++$i) {
        $header = imap_header($imap, $i);
        $body = imap_fetchbody($imap, $i,$partno);
        $prettydate = date("jS F Y", $header->udate);

        if (isset($header->from[0]->personal)) {
            $personal = $header->from[0]->personal;
        } else {
            $personal = $header->from[0]->mailbox;
        }
$body=imap_base64($body);
        $email = "$personal <{$header->from[0]->mailbox}@{$header->from[0]->host}>";
        echo "On $prettydate, $email said \"$body\".\n";
    }

    imap_close($imap);

      
      
      
      ?>
0
Comment
Question by:fox_statton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 37827042
Please see: http://php.net/manual/en/function.imap-fetchstructure.php

I've had some luck using an email "pipe" script to access all of the inbound messages for a given email address.  The server associates the pipe with an email address and instead of putting the messages into an inbox, the server starts the pipe script.  The pipe reads the email from STDIN.  Each line of the input looks exactly like what you would expect to see if you did "view source" and read the text a line at a time.
0
 

Author Closing Comment

by:fox_statton
ID: 37834890
Perfect thanks!
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 37834956
Thanks for the points!  Best of luck with your project, ~Ray
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question