PHP and POP3

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
arya6000
Forum Newbie
Posts: 15
Joined: Fri Apr 07, 2006 3:32 pm

PHP and POP3

Post by arya6000 »

Hello

I want to write a small php script that connects to my gmail pop3 account and receive the sender's email and store it in a database, I searched online but did not find anything related to php and pop3, can you help me move forward with this?

Thank You
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: PHP and POP3

Post by John Cartwright »

I'm off to bed so I won't get into this much (plus it is well documented).
Take a look at imap, and more specifically imap_open() using the /pop3 flag, which will allow you to connect to your pop3 account.

I.e.

Code: Select all

$connection = imap_open ("{gmail.com:110/pop3}INBOX", "username", "password");
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: PHP and POP3

Post by Apollo »

POP3'ing Google requires SSL.

I used PHPMailer to achieve this. See also this thread.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: PHP and POP3

Post by John Cartwright »

I would advise to avoid using PHPmailer. It has been unsupported for quite some time.

From a user comment, if you want to connect to imap with gmail you would do (source)

Code: Select all

$mbox = imap_open ("{imap.gmail.com:993/imap/ssl}INBOX", "username@gmail.com", "password")
     or die("can't connect: " . imap_last_error());
If you really want to use pop3 (slower I believe), (source)

Code: Select all

imap_open("{pop.gmail.com:995/pop3/ssl/novalidate-cert}INBOX", $username, $pasword);
User avatar
Apollo
Forum Regular
Posts: 794
Joined: Wed Apr 30, 2008 2:34 am

Re: PHP and POP3

Post by Apollo »

Jcart wrote:I would advise to avoid using PHPmailer. It has been unsupported for quite some time.
You sure? The latest version is only 2 months old, and some spin-off projects (built on PHPmailer) were updated even last week.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: PHP and POP3

Post by John Cartwright »

Ah I didn't know. Last time I checked it was a few years or so since the last update. But again.. I may be mistaken.
Post Reply