Link to home
Start Free TrialLog in
Avatar of fox_statton
fox_statton

asked on

IMAP get entire message

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);

      
      
      
      ?>
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fox_statton
fox_statton

ASKER

Perfect thanks!
Thanks for the points!  Best of luck with your project, ~Ray