Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

IMAP get entire message

Posted on 2012-04-09
3
Medium Priority
?
380 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

Independent Software Vendors: 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

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

604 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