Voorbeeld hoe te gebruiken:
<pre><?
error_reporting(E_ALL);
include('pop3.php');
$rPOP3handle = new pop3('localhost','mijnemail@mijndomijn','wachtwoord');
print_r($rPOP3handle->retrieveMessage(1));
?>


de klasse:
<?
class pop3
	{
	private $rConnection, $sUser, $sPass, $sHost, $iPort, $sReturn;
	public function __construct($sHost,$sUser,$sPass,$iPort=110)
		{
		$this->sHost = $sHost;
		$this->iPort = $iPort;
		$this->sUser = $sUser;
		$this->sPass = $sPass;
		$this->rConnection = fsockopen($sHost,$iPort,$iErrorNum, $sErrorStr,5);
		if(substr(trim($this->sReturn = $this->stream_get_contents() ),0,3) != '+OK')
			{
			$this->throwError('fsockopen:'.$sErrorStr);
			return false;
			}
		$this->toSock('USER '.$sUser);
		$this->sReturn = trim($this->stream_get_contents());
		if(substr($this->sReturn,0,3) != '+OK')
			{
			return false;
			}
		$this->toSock('PASS '.$sPass);
		$this->sReturn = trim($this->stream_get_contents());
		if(substr($this->sReturn,0,3) != '+OK')
			{
			return false;
			}
		return true;
		}
	public function __destruct()
		{
		$this->toSock('QUIT');
		fclose($this->rConnection);
		}
	private function stream_get_contents($iLength = 512)
		{
		$sReturn = fread($this->rConnection,$iLength);
		return str_replace("\r\n","\n",$sReturn);
		}
	private function toSock($sStr)
		{
		if($this->rConnection)
			{
			if(fwrite($this->rConnection,$sStr."\n")===FALSE)
				{
				return false;
				}
			else
				{
				return true;
				}
			}
		else
			{
			$this->throwError('Geen verbinding');
			return false;
			}
		}
	private function throwError($sError)
		{
		echo '<br>
		<hr>
		Er is een fout opgetreden.<br>
		De volgende fout werd meegegeven:<br>'.$sError.'<hr>
		<br>';
		}
	public function deleteMessage($iBerichtNummer)
		{
		$this->toSock('DELE '.$iBerichtNummer);
		$this->sReturn = trim($this->stream_get_contents());
		return (substr($this->sReturn,0,3) == '+OK');
		}
	public function listMessages($iBerichtNummer = '')
		{
		if(!empty($iBerichtNummer))
			{
			if(!is_numeric($iBerichtNummer))
				{
				$this->throwError('Ongeldig berichtnummer!');
				return false;
				}
			else
				{
				$this->toSock('LIST '.$iBerichtNummer);
				$this->sReturn = trim($this->stream_get_contents());
				echo "\n".$this->sReturn."\n";

				if(substr($this->sReturn,0,3) != '+OK')
					{
					return false;
					}
				$aReturnData = explode(' ',$this->sReturn);
				return array($aReturnData[1] => $aReturnData[2]);
				}
			}
		else
			{
			$this->toSock('LIST');
			echo "\ntoSock('LIST')\n";
		$this->sReturn = trim($this->stream_get_contents());
			if(substr($this->sReturn,0,3) != '+OK')
				{
				return false;
				}
			ereg("^\+OK ([0-9]*) [aegms]{8} \(([0-9]*) [ceost]{6}\)(.*)\.$",$this->sReturn,$aMatch);
			if($aMatch[1] > 0)
				{
				$aResult[0] = array($aMatch[1] => $aMatch[2]);
				$aReturnData = explode("\n",$this->sReturn);
				foreach($aReturnData as $sRij)
					{
					$aRij = explode(' ',$sRij);
					if(count($aRij) == 2)
						{
						$aResult[$aRij[0]] = $aRij[1];
						}
					}
				}
			else
				{
				$aResult = array(0=>array(0=>0));
				}
			return $aResult;
			}
		}
	public function retrieveMessage($iBerichtNummer)
		{
		$this->toSock('RETR '.$iBerichtNummer);
		$this->sReturn = trim($this->stream_get_contents());
		if(substr($this->sReturn,0,3) != '+OK')
			{
			$aReturn = false;
			}
		else
			{
			if(ereg("^\+OK ([0-9]*) [ceost]{6}\n(.*)\n\.",$this->sReturn,$aMatch))
				{
				//aMatch[1] => totale grootte bericht
				//aMatch[2] => totale bericht
				
				// is het bericht groter dan 500 bytes
				// Ja? dan is nog niet het hele bericht uitgelezen
				if($aMatch[1] > 502)
					{
					$aMatch[2] .= stream_get_contents($aMatch[1] - 512);
					}
				// Headers+bericht
				$aReturn['message'] = $aMatch[2];
				// headers worden afgesloten met een dubbele newline.
				$aReturnData = explode("\n\n",$aMatch[2]);
				$aReturn['headers'] = $aReturnData[0];
				$iHeaderLength = strlen($aReturnData[0]);
				// lengte die overblijft na het afknippen van de headers
				$aReturn['body'] = substr($aMatch[2],$iHeaderLength+2);
				}
			else
				{
				// ereg vond geen matchniet.
				$this->throwError('System: POP3-Server returned an invalid messageformat!');
				echo $this->sReturn;
				return false;
				}
			}
		return $aReturn;
		}
	}
?> 