ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
PHPMailer\PHPMailer\POP3 Class Reference

PHPMailer POP-Before-SMTP Authentication Class. More...

+ Collaboration diagram for PHPMailer\PHPMailer\POP3:

Public Member Functions

 authorise ($host, $port=false, $timeout=false, $username='', $password='', $debug_level=0)
 Authenticate with a POP3 server. More...
 
 connect ($host, $port=false, $tval=30)
 Connect to a POP3 server. More...
 
 login ($username='', $password='')
 Log in to the POP3 server. More...
 
 disconnect ()
 Disconnect from the POP3 server. More...
 
 getErrors ()
 Get an array of error messages, if any. More...
 

Static Public Member Functions

static popBeforeSmtp ( $host, $port=false, $timeout=false, $username='', $password='', $debug_level=0)
 Simple static wrapper for all-in-one POP before SMTP. More...
 

Data Fields

const VERSION = '6.1.6'
 
const DEFAULT_PORT = 110
 
const DEFAULT_TIMEOUT = 30
 
 $do_debug = 0
 
 $host
 
 $port
 
 $tval
 
 $username
 
 $password
 
const LE = "\r\n"
 Line break constant. More...
 

Protected Member Functions

 getResponse ($size=128)
 Get a response from the POP3 server. More...
 
 sendString ($string)
 Send raw data to the POP3 server. More...
 
 checkResponse ($string)
 Checks the POP3 server response. More...
 
 setError ($error)
 Add an error to the internal error store. More...
 
 catchWarning ($errno, $errstr, $errfile, $errline)
 POP3 connection error handler. More...
 

Protected Attributes

 $pop_conn
 
 $connected = false
 
 $errors = []
 

Detailed Description

PHPMailer POP-Before-SMTP Authentication Class.

Specifically for PHPMailer to use for RFC1939 POP-before-SMTP authentication. 1) This class does not support APOP authentication. 2) Opening and closing lots of POP3 connections can be quite slow. If you need to send a batch of emails then just perform the authentication once at the start, and then loop through your mail sending script. Providing this process doesn't take longer than the verification period lasts on your POP3 server, you should be fine. 3) This is really ancient technology; you should only need to use it to talk to very old systems. 4) This POP3 class is deliberately lightweight and incomplete, implementing just enough to do authentication. If you want a more complete class there are other POP3 classes for PHP available.

Author
Richard Davey (original author) rich@.nosp@m.core.nosp@m.php.c.nosp@m.o.uk
Marcus Bointon (Synchro/coolbru) phpma.nosp@m.iler.nosp@m.@sync.nosp@m.hrom.nosp@m.edia..nosp@m.co.u.nosp@m.k
Jim Jagielski (jimjag) jimja.nosp@m.g@gm.nosp@m.ail.c.nosp@m.om
Andy Prevost (codeworxtech) codew.nosp@m.orxt.nosp@m.ech@u.nosp@m.sers.nosp@m..sour.nosp@m.cefo.nosp@m.rge.n.nosp@m.et

Definition at line 41 of file POP3.php.

Member Function Documentation

◆ authorise()

PHPMailer\PHPMailer\POP3::authorise (   $host,
  $port = false,
  $timeout = false,
  $username = '',
  $password = '',
  $debug_level = 0 
)

Authenticate with a POP3 server.

A connect, login, disconnect sequence appropriate for POP-before SMTP authorisation.

Parameters
string$hostThe hostname to connect to
int | bool$portThe port number to connect to
int | bool$timeoutThe timeout value
string$username
string$password
int$debug_level
Returns
bool

Definition at line 172 of file POP3.php.

173 {
174 $this->host = $host;
175 // If no port value provided, use default
176 if (false === $port) {
177 $this->port = static::DEFAULT_PORT;
178 } else {
179 $this->port = (int) $port;
180 }
181 // If no timeout value provided, use default
182 if (false === $timeout) {
183 $this->tval = static::DEFAULT_TIMEOUT;
184 } else {
185 $this->tval = (int) $timeout;
186 }
187 $this->do_debug = $debug_level;
188 $this->username = $username;
189 $this->password = $password;
190 // Reset the error log
191 $this->errors = [];
192 // connect
193 $result = $this->connect($this->host, $this->port, $this->tval);
194 if ($result) {
195 $login_result = $this->login($this->username, $this->password);
196 if ($login_result) {
197 $this->disconnect();
198
199 return true;
200 }
201 }
202 // We need to disconnect regardless of whether the login succeeded
203 $this->disconnect();
204
205 return false;
206 }
$result
login($username='', $password='')
Log in to the POP3 server.
Definition: POP3.php:280
disconnect()
Disconnect from the POP3 server.
Definition: POP3.php:310
connect($host, $port=false, $tval=30)
Connect to a POP3 server.
Definition: POP3.php:217

References PHPMailer\PHPMailer\POP3\$host, PHPMailer\PHPMailer\POP3\$password, PHPMailer\PHPMailer\POP3\$port, $result, PHPMailer\PHPMailer\POP3\$username, PHPMailer\PHPMailer\POP3\connect(), PHPMailer\PHPMailer\POP3\disconnect(), and PHPMailer\PHPMailer\POP3\login().

+ Here is the call graph for this function:

◆ catchWarning()

PHPMailer\PHPMailer\POP3::catchWarning (   $errno,
  $errstr,
  $errfile,
  $errline 
)
protected

POP3 connection error handler.

Parameters
int$errno
string$errstr
string$errfile
int$errline

Definition at line 414 of file POP3.php.

415 {
416 $this->setError(
417 'Connecting to the POP3 server raised a PHP warning:' .
418 "errno: $errno errstr: $errstr; errfile: $errfile; errline: $errline"
419 );
420 }
setError($error)
Add an error to the internal error store.
Definition: POP3.php:384

References PHPMailer\PHPMailer\POP3\setError().

+ Here is the call graph for this function:

◆ checkResponse()

PHPMailer\PHPMailer\POP3::checkResponse (   $string)
protected

Checks the POP3 server response.

Looks for for +OK or -ERR.

Parameters
string$string
Returns
bool

Definition at line 367 of file POP3.php.

368 {
369 if (strpos($string, '+OK') !== 0) {
370 $this->setError("Server reported an error: $string");
371
372 return false;
373 }
374
375 return true;
376 }

References PHPMailer\PHPMailer\POP3\setError().

Referenced by PHPMailer\PHPMailer\POP3\connect(), and PHPMailer\PHPMailer\POP3\login().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ connect()

PHPMailer\PHPMailer\POP3::connect (   $host,
  $port = false,
  $tval = 30 
)

Connect to a POP3 server.

Parameters
string$host
int | bool$port
int$tval
Returns
bool

Definition at line 217 of file POP3.php.

218 {
219 // Are we already connected?
220 if ($this->connected) {
221 return true;
222 }
223
224 //On Windows this will raise a PHP Warning error if the hostname doesn't exist.
225 //Rather than suppress it with @fsockopen, capture it cleanly instead
226 set_error_handler([$this, 'catchWarning']);
227
228 if (false === $port) {
229 $port = static::DEFAULT_PORT;
230 }
231
232 // connect to the POP3 server
233 $errno = 0;
234 $errstr = '';
235 $this->pop_conn = fsockopen(
236 $host, // POP3 Host
237 $port, // Port #
238 $errno, // Error Number
239 $errstr, // Error Message
240 $tval
241 ); // Timeout (seconds)
242 // Restore the error handler
243 restore_error_handler();
244
245 // Did we connect?
246 if (false === $this->pop_conn) {
247 // It would appear not...
248 $this->setError(
249 "Failed to connect to server $host on port $port. errno: $errno; errstr: $errstr"
250 );
251
252 return false;
253 }
254
255 // Increase the stream time-out
256 stream_set_timeout($this->pop_conn, $tval, 0);
257
258 // Get the POP3 server response
259 $pop3_response = $this->getResponse();
260 // Check for the +OK
261 if ($this->checkResponse($pop3_response)) {
262 // The connection is established and the POP3 server is talking
263 $this->connected = true;
264
265 return true;
266 }
267
268 return false;
269 }
getResponse($size=128)
Get a response from the POP3 server.
Definition: POP3.php:329
checkResponse($string)
Checks the POP3 server response.
Definition: POP3.php:367

References PHPMailer\PHPMailer\POP3\$host, PHPMailer\PHPMailer\POP3\$port, PHPMailer\PHPMailer\POP3\$tval, PHPMailer\PHPMailer\POP3\checkResponse(), PHPMailer\PHPMailer\POP3\getResponse(), and PHPMailer\PHPMailer\POP3\setError().

Referenced by PHPMailer\PHPMailer\POP3\authorise().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ disconnect()

PHPMailer\PHPMailer\POP3::disconnect ( )

Disconnect from the POP3 server.

Definition at line 310 of file POP3.php.

311 {
312 $this->sendString('QUIT');
313 //The QUIT command may cause the daemon to exit, which will kill our connection
314 //So ignore errors here
315 try {
316 @fclose($this->pop_conn);
317 } catch (Exception $e) {
318 //Do nothing
319 }
320 }
sendString($string)
Send raw data to the POP3 server.
Definition: POP3.php:346

References PHPMailer\PHPMailer\POP3\sendString().

Referenced by PHPMailer\PHPMailer\POP3\authorise().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getErrors()

PHPMailer\PHPMailer\POP3::getErrors ( )

Get an array of error messages, if any.

Returns
array

Definition at line 401 of file POP3.php.

402 {
403 return $this->errors;
404 }

References PHPMailer\PHPMailer\POP3\$errors.

◆ getResponse()

PHPMailer\PHPMailer\POP3::getResponse (   $size = 128)
protected

Get a response from the POP3 server.

Parameters
int$sizeThe maximum number of bytes to retrieve
Returns
string

Definition at line 329 of file POP3.php.

330 {
331 $response = fgets($this->pop_conn, $size);
332 if ($this->do_debug >= 1) {
333 echo 'Server -> Client: ', $response;
334 }
335
336 return $response;
337 }
$size
Definition: RandomTest.php:84
$response

References $response, and $size.

Referenced by PHPMailer\PHPMailer\POP3\connect(), and PHPMailer\PHPMailer\POP3\login().

+ Here is the caller graph for this function:

◆ login()

PHPMailer\PHPMailer\POP3::login (   $username = '',
  $password = '' 
)

Log in to the POP3 server.

Does not support APOP (RFC 2828, 4949).

Parameters
string$username
string$password
Returns
bool

Definition at line 280 of file POP3.php.

281 {
282 if (!$this->connected) {
283 $this->setError('Not connected to POP3 server');
284 }
285 if (empty($username)) {
287 }
288 if (empty($password)) {
290 }
291
292 // Send the Username
293 $this->sendString("USER $username" . static::LE);
294 $pop3_response = $this->getResponse();
295 if ($this->checkResponse($pop3_response)) {
296 // Send the Password
297 $this->sendString("PASS $password" . static::LE);
298 $pop3_response = $this->getResponse();
299 if ($this->checkResponse($pop3_response)) {
300 return true;
301 }
302 }
303
304 return false;
305 }

References PHPMailer\PHPMailer\POP3\$password, PHPMailer\PHPMailer\POP3\$username, PHPMailer\PHPMailer\POP3\checkResponse(), PHPMailer\PHPMailer\POP3\getResponse(), PHPMailer\PHPMailer\POP3\sendString(), and PHPMailer\PHPMailer\POP3\setError().

Referenced by PHPMailer\PHPMailer\POP3\authorise().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ popBeforeSmtp()

static PHPMailer\PHPMailer\POP3::popBeforeSmtp (   $host,
  $port = false,
  $timeout = false,
  $username = '',
  $password = '',
  $debug_level = 0 
)
static

Simple static wrapper for all-in-one POP before SMTP.

Parameters
string$hostThe hostname to connect to
int | bool$portThe port number to connect to
int | bool$timeoutThe timeout value
string$username
string$password
int$debug_level
Returns
bool

Definition at line 145 of file POP3.php.

152 {
153 $pop = new self();
154
155 return $pop->authorise($host, $port, $timeout, $username, $password, $debug_level);
156 }

References PHPMailer\PHPMailer\POP3\$host, PHPMailer\PHPMailer\POP3\$password, PHPMailer\PHPMailer\POP3\$port, and PHPMailer\PHPMailer\POP3\$username.

◆ sendString()

PHPMailer\PHPMailer\POP3::sendString (   $string)
protected

Send raw data to the POP3 server.

Parameters
string$string
Returns
int

Definition at line 346 of file POP3.php.

347 {
348 if ($this->pop_conn) {
349 if ($this->do_debug >= 2) { //Show client messages when debug >= 2
350 echo 'Client -> Server: ', $string;
351 }
352
353 return fwrite($this->pop_conn, $string, strlen($string));
354 }
355
356 return 0;
357 }

Referenced by PHPMailer\PHPMailer\POP3\disconnect(), and PHPMailer\PHPMailer\POP3\login().

+ Here is the caller graph for this function:

◆ setError()

PHPMailer\PHPMailer\POP3::setError (   $error)
protected

Add an error to the internal error store.

Also display debug output if it's enabled.

Parameters
string$error

Definition at line 384 of file POP3.php.

385 {
386 $this->errors[] = $error;
387 if ($this->do_debug >= 1) {
388 echo '<pre>';
389 foreach ($this->errors as $e) {
390 print_r($e);
391 }
392 echo '</pre>';
393 }
394 }

Referenced by PHPMailer\PHPMailer\POP3\catchWarning(), PHPMailer\PHPMailer\POP3\checkResponse(), PHPMailer\PHPMailer\POP3\connect(), and PHPMailer\PHPMailer\POP3\login().

+ Here is the caller graph for this function:

Field Documentation

◆ $connected

PHPMailer\PHPMailer\POP3::$connected = false
protected

Definition at line 119 of file POP3.php.

◆ $do_debug

PHPMailer\PHPMailer\POP3::$do_debug = 0

Definition at line 70 of file POP3.php.

◆ $errors

PHPMailer\PHPMailer\POP3::$errors = []
protected

Definition at line 126 of file POP3.php.

Referenced by PHPMailer\PHPMailer\POP3\getErrors().

◆ $host

PHPMailer\PHPMailer\POP3::$host

◆ $password

PHPMailer\PHPMailer\POP3::$password

◆ $pop_conn

PHPMailer\PHPMailer\POP3::$pop_conn
protected

Definition at line 112 of file POP3.php.

◆ $port

PHPMailer\PHPMailer\POP3::$port

◆ $tval

PHPMailer\PHPMailer\POP3::$tval

Definition at line 91 of file POP3.php.

Referenced by PHPMailer\PHPMailer\POP3\connect().

◆ $username

PHPMailer\PHPMailer\POP3::$username

◆ DEFAULT_PORT

const PHPMailer\PHPMailer\POP3::DEFAULT_PORT = 110

Definition at line 55 of file POP3.php.

◆ DEFAULT_TIMEOUT

const PHPMailer\PHPMailer\POP3::DEFAULT_TIMEOUT = 30

Definition at line 62 of file POP3.php.

◆ LE

const PHPMailer\PHPMailer\POP3::LE = "\r\n"

Line break constant.

Definition at line 131 of file POP3.php.

◆ VERSION

const PHPMailer\PHPMailer\POP3::VERSION = '6.1.6'

Definition at line 48 of file POP3.php.


The documentation for this class was generated from the following file: