The article above is a good one, but I have to warn you: Not all mail servers on the net user proper message encoding, which makes the above method a PITA. I used to use the above method for checking mail and had all kinds of problems recieving mail from Yahoo (in particular).
The better solution is to use the PHP IMAP functions for retrieving POP mail. They are MUCH easier than trying to figure it all out on your own.