Well, let me give you the following then:
class POP3Mail
{
function Connect ( $HOST , $PORT , $TIMEOUT , $USERNAME , $PASSWORD )
{
$port = ( $PORT ) ? $PORT : "110";
$timeout = ( $TIMEOUT ) ? $TIMEOUT : "60";
$this->MyConnection = fsockopen( $HOST , $port , &$en , &$ed , $timeout );
if ( ! $this->MyConnection )
{
return "111"; /* Unable to Connect to Host */
}
$this->Listen();
$response = $this->Ask( "USER $USERNAME" );
if ( $this->isError( $response ) )
{
return "121"; /* Invalid Username */
}
$response = $this->Ask( "PASS $PASSWORD" );
if ( $this->isError( $response ) )
{
return "122"; /* Invalid Password */
}
$stats = explode ( " " , $this->Ask( "STAT" ) );
$this->MailboxMessages = $stats[1];
$this->MailboxSize = $stats[2];
return "OK";
}
function GetMessage ( $message )
{
$body = $this->Ask( "RETR $message" , 1 );
if ( $this->isError( $body[0] ) )
{
return "301"; /* Invalid RETR command */
}
array_shift( $body );
return $body;
}
function DeleteMessage ( $message )
{
$this->Say( "DELE $message" );
}
function MessageCount ()
{
return $this->MailboxMessages;
}
function Disconnect ()
{
$this->Say( "QUIT" );
fclose( $this->MyConnection );
}
function Ask ( $command , $longanswer = 0 )
{
$this->Say( $command );
$response = $this->Listen();
if ( $longanswer )
{
while ( ! ( trim( $response ) == "." ) )
{
if ( ! ( trim( $response ) == "." ) )
{
$answer[] .= $response;
$response = $this->Listen();
}
}
$response = $answer;
}
return $response;
}
function Say ( $command )
{
fputs ( $this->MyConnection , $command."\r\n" );
}
function Listen ()
{
return fgets ( $this->MyConnection , $this->MyBuffer );
}
function isError ( $response )
{
return ( substr( $line, 0, 3 ) == "-ER" ) ? TRUE : FALSE;
}
}
Hope it's understandable...I had to strip it from a larger project. Here's how it should work:
$email = new POP3Mail;
$email->Connect($host,$port,$timtout,$username,$password);
for ($x = 0;$x<=$email->MessageCount;$x++)
{
$MyMessages[$x] = $email->GetMessage( $x );
$email->DeleteMessage( $x );
}
$email->Disconnect();
Hope this works for you! Let me know if it doesn't!
Lewis