Hi,
Can someone help me make a php script that can get an email from my email inbox on my server and echo it on to the screen?
Thanks,
Alex

    This script will give you a listing of your messages in your Inbox folder with the first 50 characters of the subject line;

    $mbox = imap_open ("{localhost:143/notls}Inbox", $username, $password) or die("can't connect: " . imap_last_error());
    echo "<p><h2>Messages in Inbox</h2>\n";
    for ($i = 1; $i <= imap_num_msg($mbox); $i++) {
          $header = imap_fetchheader ($mbox,$i);
          $first=strstr($header, "Subject:");
          $subject=substr($first, 0,50);
          echo "Msg. # $i - $subject [<a href='view_mail.php?message=$i&username=$username&password=$password'>View Message</a>]<br>\n";
    }
    
    imap_close($mbox);

    And this will display a single message with the header in one text box and the body in anaother.

    $mbox = imap_open ("{localhost:143/notls}Inbox", $username, $password);
    $header = imap_fetchheader ($mbox,$message);
    echo "<textarea  cols='100' rows='25' wrap>$header</textarea>\n";
    $body = imap_body ($mbox, $message, FT_PEEK);
    echo "<p><textarea  cols='100' rows='25' wrap>$body</textarea>\n";      
    imap_close($mbox);

      Thanks for you help, it looks good. Ill test it when i get back from school.
      Alex

        for some reason it apears not to work and gives me the following error:

        Fatal error: Call to undefined function: imap_open() in /home/www/**************/emails/inbox.php on line 3

          I guess maybe your php was not compiled with imap support??

            no, it's the only way to access an email server, I think.

              There are various POP3 and/or IMAP class out there you could try, e.g. the Pear Net_POP3 package. Doing a web search on "PHP POP3 class" will turn up a number of others.

                Write a Reply...