WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : POP3 Class
Categories : PHP Classes, PHP, Email Update Picture
Leandro López
Date : Jul 26th 2000
Grade : 4 of 5 (graded 4 times)
Viewed : 10823
File : pop3.class.inc
Images : No Images for this code example.
Search : More code by Leandro López
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?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();
}
*/
?>



Class for sending mail with MIME attachments in multipart format using external sendmail, mimencode and zip
Categories : Email, Network, PHP, PHP Classes
Validator - A PHP class that can can be used for validating Email IDs and Dates
Categories : PHP, PHP Classes, Data Validation, Email, Date Time
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
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
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
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
Authorize.net AIM Interface Class v1.0.0
Categories : PHP, PHP Classes, Ecommerce, Payment Gateways
A simple class with some HTML output functions that would come in handy for consistent page layout etc.
Categories : PHP, PHP Classes, HTML and PHP, HTML, Navigation
crop and resize image class using gd library function
Categories : PHP, PHP Classes, GD image library, Graphics
Excel class in PHP
Categories : PHP, PHP Classes, Excel
News management class
Categories : PHP, PHP Classes, Beginner Guides
Expose - PHP template engine, supports server and client-sided caching,a plugin system, multiple languages, template script language is based on PHP itself.
Categories : PHP, PHP Classes, Templates, Complete Programs
Simple Template Class/Example
Categories : PHP, Templates, PHP Classes
 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