<?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();
}
}
/*
include('./pop3.class.inc');
$pop3 = new POP3;
$pop3->server = "your.mail.server";
$pop3->user = "you";
$pop3->passwd = "youknow";
$pop3->debug = true; // So you can see the commands and server answers
header("Content-type: text/plain");
if($pop3->pop3_connect()) {
$pop3->pop3_login();
$pop3->pop3_stat();
if($pop3->pop3_list())
while($line = $pop3->nextAnswer())
echo $line;
$pop3->pop3_list(1);
if($pop3->pop3_top(1,0))
while($line = $pop3->nextAnswer())
echo $line;
if($pop3->pop3_retr(1))
while($line = $pop3->nextAnswer())
echo $line;
$pop3->pop3_disconnect();
}
*/
?>
Validator - A PHP class that can can be used for validating Email IDs and Dates Categories : PHP , PHP Classes , Data Validation , Email , Date Time Three Cool Classes and One Trick Categories : PHP , PHP Classes , Graphics , Email Class that allows the PHP developer to establish connections with a POP3 mail server amd be able to list, retrieve and delete mail messages from a given mail box.
Categories : Network , Email , PHP , PHP Classes EAvalidator - This class can be used to validate an e-mail address by checking its domain. Categories : PHP , PHP Classes , Email , Regexps cPanel Email Accounts Creator Categories : PHP , PHP Classes , Email , Form Processing , Web Services A class for sending email; it has support for To:, Cc:, Bcc: and Reply-To:
headers. It requires that you have sendmail installed. Categories : Email , PHP Classes , PHP Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip Categories : Email , Network , PHP , PHP Classes PHP MIME Decoder. This class decodes Mime Encoded email message.
Attachments are stored in a director. Works with Multipart/alternative,
multipart/mixed etc.
see http://p3mail.com for example. Categories : PHP , PHP Classes , Email Protect your mailto: email addresses from bots Categories : PHP , Email , Java Script Class: Info on Users, Servers and the running script Categories : PHP , Classes and Objects , User Interface , PHP Classes XTemplate, a template class for PHP Categories : PHP Classes , HTML and PHP , PHP Ajax PHP Tree (Left and Right) with MySQL Categories : PHP , Databases , MySQL , AJAX , PHP Classes YellowPages Content Grabber (PHP5 +) Categories : PHP , PHP Classes , Regexps , Databases , MySQL AutoCMS - This class can be used to generate a basic content site. Categories : PHP , Content Management , PHP Classes Simple class that uses GD to draw pie charts. After the class definition there's some sample code to demonstrate how you use the class.
Categories : Graphics , PHP , PHP Classes , GD image library , Charts and Graphs
Prachya Pantuyakorn wrote : 600
Hi, I`ve tested ur script. It`s very useful. Would u pls give me and idea to create mailbox by using php cript?
Best regard,
Prachya