jeg ved ikke om alt det her kan stå i denne box men nu prøver jeg... Jeg undskylder rodet, men jeg har aldrig lavet dette projekt helt færdigt.
Denne fil kalder jeg for pop3.class.inc.php (dette er en include fil)
<?php
/*
This is a class for connect to a POP3 Mail Server. This is version 1.0
It was developed based on the RFC 1939
Suggestions, critics or whatever you want, feel free of send it to me at my personal email:
inKel@sion.com
My english sucks, \'cause I\'m from Argentina
ToDo:
. analize the advantgaes of using a persistent connection
. documentation!!!!
. create a better example (I\'m currently on this)
. study a little of english =)
At the end of the file you could find an example of use
*/
class POP3 {
var $server; // POP 3 Server Address
var $port = 110;// POP 3 Server Port
var $sockfd; // Socket Descriptor
var $user; // POP 3 Mailbox User ID
var $passwd; // POP 3 Mailbox User Password
var $answer; // POP 3 Server Answer
var $mailsize; // Mail size
var $mailno; // Mail number
var $mailboxno; // Number of mails in mailbox
var $mailboxsize; // How many bytes are you using in you mailbox
var $debug = true; // Debug Class
/*
bool cmdOK(): Return true if the server validates the cmd, else return false;
*/
function cmdOK() {
$this->answer = fgets($this->sockfd, 2048);
if($this->debug) echo \"\\nS: $this->answer\";
if(ereg(\"^\\+OK\", $this->answer))
return true;
else
return false;
}
function sendCmd($cmd, $param1 = \'\', $param2 = \'\') {
if($this->debug) echo \"\\nC:$cmd $param1 $param2\";
fwrite($this->sockfd, trim(\"$cmd $param1 $param2\") . \"\\r\\n\");
}
function nextAnswer() {
$line = fgets($this->sockfd, 2048);
return (ereg(\"^\\.\\r\\n$\", $line)?false:$line);
}
/*
bool pop3_connect(blocking mode): Connects to POP3 server and return true if succesful,
else return false
*/
function pop3_connect($block = \'true\') {
if($this->sockfd = fsockopen($this->server, $this->port)) {
if($this->cmdOK()) {
//set_socket_blocking($this->sockfd, $block);
return true;
}
}
return false;
}
function pop3_disconnect() {
fwrite($this->sockfd, \"QUIT\\r\\n\");
$this->cmdOK();
fclose($this->sockfd);
}
function pop3_login() {
$this->sendCmd(\"USER\", $this->user);
if($this->cmdOK()) {
$this->sendCmd(\"PASS\", $this->passwd);
if($this->cmdOK()) {
return true;
}
}
return false;
}
function pop3_stat() {
$this->sendCmd(\"STAT\");
$state = $this->cmdOK();
if(ereg(\"^\\+OK ([0-9]+) ([0-9]+)\", $this->answer, $aux)) {
$this->mailboxno = $aux[1];
$this->mailboxsize = $aux[2];
}
return $state;
}
function pop3_list($mailno = \'\') {
$this->sendCmd(\"LIST\", $mailno);
$state = $this->cmdOK();
if(ereg(\"^\\+OK ([0-9]+) ([0-9]+)\", $this->answer, $aux)) {
$this->mailno = $aux[1];
$this->mailsize = $aux[2];
}
return $state;
}
function pop3_top($mailno = 1, $lines = 0) {
$this->sendCmd(\"TOP\", $mailno, $lines);
return $this->cmdOK();
}
function pop3_retr($mailno = 1) {
$this->sendCmd(\"RETR\", $mailno);
return $this->cmdOK();
}
function pop3_dele($mailno = 1) {
$this->sendCmd(\"DELE\", $mailno);
return $this->cmdOK();
}
function pop3_rset() {
$this->sendCmd(\"RSET\");
return $this->cmdOK();
}
function pop3_noop() {
$this->sendCmd(\"NOOP\");
return $this->cmdOK();
}
function pop3_uidl($mailno = \'\') {
$this->sendCmd(\"UIDL\", $mailno);
return $this->cmdOK();
}
}
?>
Dette er selve hoved-filen (jeg kalder den pop3.php)
<?php
header(\"Content-type: text/plain\");
include(\'pop3.class.inc.php\');
$month = array(\"Jan\"=>\"1\",\"Feb\"=>\"2\",\"Mar\"=>\"3\",\"Apr\"=>\"4\",\"May\"=>\"5\",\"Jun\"=>\"6\",\"Jul\"=>\"7\",\"Aug\"=>\"8\",\"Sep\"=>\"9\",\"Oct\"=>\"10\",\"Nov\"=>\"11\",\"Dec\"=>\"12\");
$pop3 = new POP3;
$pop3->server = \"domain.com\";
$pop3->user = \"test\";
$pop3->passwd = \"password\";
$pop3->debug = false;
if($pop3->pop3_connect()) {
$pop3->pop3_login();
$pop3->pop3_stat();
$loop=1;
while($loop <= $pop3->mailboxno){
if($pop3->pop3_top($loop,0))
while($line = $pop3->nextAnswer()){
if(eregi(\"From:\",$line))$info[from]=trim($line);
if(eregi(\"Subject:\",$line))$info[subject]=trim($line);
if(eregi(\"Date:\",$line))$info[idate]=trim($line);
}
$info[subject] = eregi_replace(\"Subject: \",\"\",$info[subject]);
if(eregi(\"iso-8859\",$info[subject])){
$info[subject] = eregi_replace(\"\\=\\?iso-8859-1\\?Q\\?\",\"\",$info[subject]);
$info[subject] = eregi_replace(\"\\?\\=$\",\"\",$info[subject]);
$info[subject] = eregi_replace(\"_\",\" \",$info[subject]);
$info[subject] = eregi_replace(\"=E6\",\"æ\",$info[subject]);
$info[subject] = eregi_replace(\"=F8\",\"ø\",$info[subject]);
$info[subject] = eregi_replace(\"=E5\",\"å\",$info[subject]);
$info[subject] = eregi_replace(\"=3A\",\":\",$info[subject]);
$info[subject] = eregi_replace(\"=2E\",\".\",$info[subject]);
$info[subject] = eregi_replace(\"=C6\",\"Æ\",$info[subject]);
$info[subject] = eregi_replace(\"=D8\",\"Ø\",$info[subject]);
$info[subject] = eregi_replace(\"=C5\",\"Å\",$info[subject]);
$info[subject] = eregi_replace(\"=A7\",\"§\",$info[subject]);
$info[subject] = eregi_replace(\"=21\",\"!\",$info[subject]);
$info[subject] = eregi_replace(\"=22\",\"\\\"\",$info[subject]);
$info[subject] = eregi_replace(\"=23\",\"#\",$info[subject]);
$info[subject] = eregi_replace(\"=A4\",\"¤\",$info[subject]);
$info[subject] = eregi_replace(\"=25\",\"%\",$info[subject]);
$info[subject] = eregi_replace(\"=26\",\"&\",$info[subject]);
$info[subject] = eregi_replace(\"=22\",\"(\",$info[subject]);
$info[subject] = eregi_replace(\"=28\",\")\",$info[subject]);
$info[subject] = eregi_replace(\"=29\",\"=\",$info[subject]);
//$info[subject] = eregi_replace(\"=22\",\"?\",$info[subject]);
//$info[subject] = eregi_replace(\"=22\",\"`\",$info[subject]);
}
eregi(\": (.*)\\<(.*)\\>\",$info[from],$info[from]);
$info[date] = split(\" \",$info[idate]);
echo($info[from][1].\"\\n\");
echo($info[subject].\"\\n\");
echo(trim($info[date][2]).\"/\");
$aim = trim($info[date][3]);
echo($month[$aim].\"-\");
echo(trim($info[date][4]).\" - \");
echo(trim($info[date][5]));
echo(\"\\n\\n\");
$loop++;
}
$pop3->pop3_disconnect();
}
?>
Jeg vil håbe at du kan bruge dette.