tags:

views:

73

answers:

3

I am trying to fetch a mail from POP3 (I am using POP3 mail server and I am trying to fetch the mail content and store into a database table for my project.), but I can't find any PHP script for that, all are only for IMAP.

Do you know how to fetch mail from a POP3 server?

Thanks.

A: 

IF you have PHP build with IMAP support, it would be easy, see IMAP documantation (especially comments at this page) at http://php.net/manual/en/book.imap.php

UPDATE: to clarify my answer - as you see in the comments and function reference, PHP imap_* functions can be used also for pop3.

Tomasz Struczyński
+2  A: 

PHP's IMAP functions can deal with both IMAP and POP3 boxes.

These functions enable you to operate with the IMAP protocol, as well as the NNTP, POP3 and local mailbox access methods.

Be warned, however, that some IMAP functions will not work correctly with the POP protocol.

there is a User Contributed Note that provides an interesting snippet. You may want to take a look at it. I can't say anything about its quality but from the surface, it looks okay.

Pekka
+1  A: 

Somewhat surprisingly, PHP's imap library can be also used for working with POP3 mailboxes. Most of the advanced IMAP features won't work, of course (e.g. folders or fetching message parts), but the basic POP3 functionality is implemented.

The main difference is the option string that you're passing to imap_open - to quote that page:

// To connect to a POP3 server on port 110 on the local server, use:
$mbox = imap_open ("{localhost:110/pop3}INBOX", "user_id", "password");

Other than that, it's fair sailing - you won't need more than imap_open, imap_num_msg, imap_body, imap_delete and imap_close for basic POP3 access.

Piskvor