Source for file pop3.php
Documentation is available at pop3.php
.---------------------------------------------------------------------------.
| Software: PHPMailer - PHP email class |
| Site: https://github.com/PHPMailer/PHPMailer/ |
| ------------------------------------------------------------------------- |
| Admins: Marcus Bointon |
| Admins: Jim Jagielski |
| Authors: Andy Prevost (codeworxtech) codeworxtech@users.sourceforge.net |
| : Marcus Bointon (coolbru) coolbru@users.sourceforge.net |
| : Jim Jagielski (jimjag) jimjag@gmail.com |
| Founder: Brent R. Matzelle (original founder) |
| Copyright (c) 2010-2012, Jim Jagielski. All Rights Reserved. |
| Copyright (c) 2004-2009, Andy Prevost. All Rights Reserved. |
| Copyright (c) 2001-2003, Brent R. Matzelle |
| ------------------------------------------------------------------------- |
| License: Distributed under the Lesser General Public License (LGPL) |
| http://www.gnu.org/copyleft/lesser.html |
| This program is distributed in the hope that it will be useful - WITHOUT |
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| FITNESS FOR A PARTICULAR PURPOSE. |
'---------------------------------------------------------------------------'
* PHPMailer - PHP POP Before SMTP Authentication Class
* NOTE: Designed for use with PHP version 5 and up
* @copyright 2010 - 2012 Jim Jagielski
* @copyright 2004 - 2009 Andy Prevost
* @license http://www.gnu.org/copyleft/lesser.html Distributed under the Lesser General Public License (LGPL)
* PHP POP-Before-SMTP Authentication Class
* @license: LGPL, see PHPMailer License
* Specifically for PHPMailer to allow POP before SMTP authentication.
* Does not yet work with APOP - if you have an APOP account, contact Jim Jagielski
* and we can test changes to this script.
* This class is based on the structure of the SMTP class originally authored by Chris Ryan
* This class is rfc 1939 compliant and implements all the commands
* required for POP3 connection, authentication and disconnection.
* @author Richard Davey (orig) <rich@corephp.co.uk>
* POP3 Carriage Return + Line Feed
* Displaying Debug warnings? (0 = now, 1+ = yes)
* Sets the POP3 PHPMailer Version number
/////////////////////////////////////////////////
// PROPERTIES, PRIVATE AND PROTECTED
/////////////////////////////////////////////////
* @var resource Resource handle for the POP connection socket
* @var boolean Are we connected?
* @var array Error container
private $error; // Error log array
* Constructor, sets the initial values
$this->connected =
false;
* Combination of public events - connect, login, disconnect
* @param string $username
* @param string $password
* @param int $debug_level
public function Authorise ($host, $port =
false, $tval =
false, $username, $password, $debug_level =
0) {
// If no port value is passed, retrieve it
// If no port value is passed, retrieve it
// We need to disconnect regardless if the login succeeded
* Connect to the POP3 server
public function Connect ($host, $port =
false, $tval =
30) {
// Are we already connected?
On Windows this will raise a PHP Warning error if the hostname doesn't exist.
Rather than suppress it with @fsockopen, let's capture it cleanly instead
// Connect to the POP3 server
$this->pop_conn =
fsockopen($host, // POP3 Host
$errstr, // Error Message
$tval); // Timeout (seconds)
// Restore the error handler
// Does the Error Log now contain anything?
if ($this->error &&
$this->do_debug >=
1) {
if ($this->pop_conn ==
false) {
// It would appear not...
'error' =>
"Failed to connect to server $host on port $port",
// Increase the stream time-out
// Check for PHP 4.3.0 or later
// Does not work on Windows
if (substr(PHP_OS, 0, 3) !==
'WIN') {
// Get the POP3 server response
$pop3_response =
$this->getResponse();
if ($this->checkResponse($pop3_response)) {
// The connection is established and the POP3 server is talking
* Login to the POP3 server (does not support APOP yet)
* @param string $username
* @param string $password
public function Login ($username =
'', $password =
'') {
if ($this->connected ==
false) {
$this->error =
'Not connected to POP3 server';
$pop_username =
"USER $username" .
$this->CRLF;
$pop_password =
"PASS $password" .
$this->CRLF;
$this->sendString($pop_username);
$pop3_response =
$this->getResponse();
if ($this->checkResponse($pop3_response)) {
$this->sendString($pop_password);
$pop3_response =
$this->getResponse();
if ($this->checkResponse($pop3_response)) {
* Disconnect from the POP3 server
$this->sendString('QUIT');
/////////////////////////////////////////////////
/////////////////////////////////////////////////
* Get the socket response back.
* $size is the maximum number of bytes to retrieve
private function getResponse ($size =
128) {
$pop3_response =
fgets($this->pop_conn, $size);
* Send a string down the open socket connection to the POP3 server
private function sendString ($string) {
$bytes_sent =
fwrite($this->pop_conn, $string, strlen($string));
* Checks the POP3 server response for +OK or -ERR
private function checkResponse ($string) {
if (substr($string, 0, 3) !==
'+OK') {
'error' =>
"Server reported an error: $string",
* If debug is enabled, display the error message array
private function displayErrors () {
foreach ($this->error as $single_error) {
* Takes over from PHP for the socket warning handler
* @param integer $errline
private function catchWarning ($errno, $errstr, $errfile, $errline) {
'error' =>
"Connecting to the POP3 server raised a PHP warning: ",
Documentation generated on Tue, 19 Nov 2013 15:10:54 +0100 by phpDocumentor 1.4.3