Accessing email content using NetPop3
July 19th, 2010 | PhpNetPop3 is a class to allow access to POP3 servers. It supports all POP3 commands including UIDL listings and APOP authentication.
Download the package first at http://pear.php.net/package/Net_POP3/download
Create a php file and include the NetPop3 at the beginning of the file
include 'POP3.php';
Connect and login using connect() and login(). Enter the host, email and password.
$pop3->connect( mail.host.com , "110" ); $pop3->login( email , password, 'USER' ) )
You can set an error prompt to determine if you can access your specified email account.
if(PEAR::isError( $ret= $pop3->connect( mail.host.com , "110" ) ) )
{
die("Cannot connect to your account");
}
if(PEAR::isError( $ret = $pop3->login( email , password, 'USER' ) ) )
{
die("Cannot login to your account");
}
To get the email body, use $pop3->getBody( email_number ). Since we use 1, the script will get the first email content. To get all the email content, use for loop.
htmlspecialchars($pop3->getBody(1))
There are other functions that are available. These are:
- getParsedHeaders( email_number ) – get structured headers of message
- numMsg() – get number of messages in maildrop
- getMsg() – get entire message
- getListing() – get listing details of the maildrop
- getSize() – get size of maildrop
Leave a Reply