Solved

IMAP get entire message

Posted on 2012-04-09
3
372 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
  • 2
3 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 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 109

Expert Comment

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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

778 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