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

PHPMailer RFC821 SMTP email transport class. More...

+ Collaboration diagram for PHPMailer\PHPMailer\SMTP:

Public Member Functions

 connect ($host, $port=null, $timeout=30, $options=[])
 Connect to an SMTP server. More...
 
 startTLS ()
 Initiate a TLS (encrypted) session. More...
 
 authenticate ( $username, $password, $authtype=null, $OAuth=null)
 Perform SMTP authentication. More...
 
 connected ()
 Check connection state. More...
 
 close ()
 Close the socket and clean up the state of the class. More...
 
 data ($msg_data)
 Send an SMTP DATA command. More...
 
 hello ($host='')
 Send an SMTP HELO or EHLO command. More...
 
 mail ($from)
 Send an SMTP MAIL command. More...
 
 quit ($close_on_error=true)
 Send an SMTP QUIT command. More...
 
 recipient ($address, $dsn='')
 Send an SMTP RCPT command. More...
 
 reset ()
 Send an SMTP RSET command. More...
 
 sendAndMail ($from)
 Send an SMTP SAML command. More...
 
 verify ($name)
 Send an SMTP VRFY command. More...
 
 noop ()
 Send an SMTP NOOP command. More...
 
 turn ()
 Send an SMTP TURN command. More...
 
 client_send ($data, $command='')
 Send raw data to the server. More...
 
 getError ()
 Get the latest error. More...
 
 getServerExtList ()
 Get SMTP extensions available on the server. More...
 
 getServerExt ($name)
 Get metadata about the SMTP server from its HELO/EHLO response. More...
 
 getLastReply ()
 Get the last reply from the server. More...
 
 setVerp ($enabled=false)
 Enable or disable VERP address generation. More...
 
 getVerp ()
 Get VERP address generation mode. More...
 
 setDebugOutput ($method='echo')
 Set debug output method. More...
 
 getDebugOutput ()
 Get debug output method. More...
 
 setDebugLevel ($level=0)
 Set debug output level. More...
 
 getDebugLevel ()
 Get debug output level. More...
 
 setTimeout ($timeout=0)
 Set SMTP timeout. More...
 
 getTimeout ()
 Get SMTP timeout. More...
 
 getLastTransactionID ()
 Get the queue/transaction ID of the last SMTP transaction If no reply has been received yet, it will return null. More...
 

Data Fields

const VERSION = '6.1.6'
 
const LE = "\r\n"
 
const DEFAULT_PORT = 25
 
const MAX_LINE_LENGTH = 998
 
const MAX_REPLY_LENGTH = 512
 
const DEBUG_OFF = 0
 
const DEBUG_CLIENT = 1
 
const DEBUG_SERVER = 2
 
const DEBUG_CONNECTION = 3
 
const DEBUG_LOWLEVEL = 4
 
 $do_debug = self::DEBUG_OFF
 
 $Debugoutput = 'echo'
 
 $do_verp = false
 
 $Timeout = 300
 
 $Timelimit = 300
 

Protected Member Functions

 edebug ($str, $level=0)
 Output debugging info via a user-selected method. More...
 
 hmac ($data, $key)
 Calculate an MD5 HMAC hash. More...
 
 sendHello ($hello, $host)
 Send an SMTP HELO or EHLO command. More...
 
 parseHelloFields ($type)
 Parse a reply to HELO/EHLO command to discover server extensions. More...
 
 sendCommand ($command, $commandstring, $expect)
 Send a command to an SMTP server and check its return code. More...
 
 get_lines ()
 Read the SMTP server's response. More...
 
 setError ($message, $detail='', $smtp_code='', $smtp_code_ex='')
 Set error messages and codes. More...
 
 errorHandler ($errno, $errmsg, $errfile='', $errline=0)
 Reports an error number and string. More...
 
 recordLastTransactionID ()
 Extract and return the ID of the last SMTP transaction based on a list of patterns provided in SMTP::$smtp_transaction_id_patterns. More...
 

Protected Attributes

 $smtp_transaction_id_patterns
 
 $last_smtp_transaction_id
 
 $smtp_conn
 
 $error
 
 $helo_rply
 
 $server_caps
 
 $last_reply = ''
 

Detailed Description

PHPMailer RFC821 SMTP email transport class.

Implements RFC 821 SMTP commands and provides some utility methods for sending mail to an SMTP server.

Author
Chris Ryan
Marcus Bointon phpma.nosp@m.iler.nosp@m.@sync.nosp@m.hrom.nosp@m.edia..nosp@m.co.u.nosp@m.k

Definition at line 30 of file SMTP.php.

Member Function Documentation

◆ authenticate()

PHPMailer\PHPMailer\SMTP::authenticate (   $username,
  $password,
  $authtype = null,
  $OAuth = null 
)

Perform SMTP authentication.

Must be run after hello().

See also
hello()
Parameters
string$usernameThe user name
string$passwordThe password
string$authtypeThe auth type (CRAM-MD5, PLAIN, LOGIN, XOAUTH2)
OAuth$OAuthAn optional OAuth instance for XOAUTH2 authentication
Returns
bool True if successfully authenticated

Definition at line 448 of file SMTP.php.

References $password, $response, PHPMailer\PHPMailer\SMTP\edebug(), PHPMailer\PHPMailer\SMTP\hmac(), PHPMailer\PHPMailer\SMTP\sendCommand(), and PHPMailer\PHPMailer\SMTP\setError().

453  {
454  if (!$this->server_caps) {
455  $this->setError('Authentication is not allowed before HELO/EHLO');
456 
457  return false;
458  }
459 
460  if (array_key_exists('EHLO', $this->server_caps)) {
461  // SMTP extensions are available; try to find a proper authentication method
462  if (!array_key_exists('AUTH', $this->server_caps)) {
463  $this->setError('Authentication is not allowed at this stage');
464  // 'at this stage' means that auth may be allowed after the stage changes
465  // e.g. after STARTTLS
466 
467  return false;
468  }
469 
470  $this->edebug('Auth method requested: ' . ($authtype ?: 'UNSPECIFIED'), self::DEBUG_LOWLEVEL);
471  $this->edebug(
472  'Auth methods available on the server: ' . implode(',', $this->server_caps['AUTH']),
473  self::DEBUG_LOWLEVEL
474  );
475 
476  //If we have requested a specific auth type, check the server supports it before trying others
477  if (null !== $authtype && !in_array($authtype, $this->server_caps['AUTH'], true)) {
478  $this->edebug('Requested auth method not available: ' . $authtype, self::DEBUG_LOWLEVEL);
479  $authtype = null;
480  }
481 
482  if (empty($authtype)) {
483  //If no auth mechanism is specified, attempt to use these, in this order
484  //Try CRAM-MD5 first as it's more secure than the others
485  foreach (['CRAM-MD5', 'LOGIN', 'PLAIN', 'XOAUTH2'] as $method) {
486  if (in_array($method, $this->server_caps['AUTH'], true)) {
487  $authtype = $method;
488  break;
489  }
490  }
491  if (empty($authtype)) {
492  $this->setError('No supported authentication methods found');
493 
494  return false;
495  }
496  $this->edebug('Auth method selected: ' . $authtype, self::DEBUG_LOWLEVEL);
497  }
498 
499  if (!in_array($authtype, $this->server_caps['AUTH'], true)) {
500  $this->setError("The requested authentication method \"$authtype\" is not supported by the server");
501 
502  return false;
503  }
504  } elseif (empty($authtype)) {
505  $authtype = 'LOGIN';
506  }
507  switch ($authtype) {
508  case 'PLAIN':
509  // Start authentication
510  if (!$this->sendCommand('AUTH', 'AUTH PLAIN', 334)) {
511  return false;
512  }
513  // Send encoded username and password
514  if (!$this->sendCommand(
515  'User & Password',
516  base64_encode("\0" . $username . "\0" . $password),
517  235
518  )
519  ) {
520  return false;
521  }
522  break;
523  case 'LOGIN':
524  // Start authentication
525  if (!$this->sendCommand('AUTH', 'AUTH LOGIN', 334)) {
526  return false;
527  }
528  if (!$this->sendCommand('Username', base64_encode($username), 334)) {
529  return false;
530  }
531  if (!$this->sendCommand('Password', base64_encode($password), 235)) {
532  return false;
533  }
534  break;
535  case 'CRAM-MD5':
536  // Start authentication
537  if (!$this->sendCommand('AUTH CRAM-MD5', 'AUTH CRAM-MD5', 334)) {
538  return false;
539  }
540  // Get the challenge
541  $challenge = base64_decode(substr($this->last_reply, 4));
542 
543  // Build the response
544  $response = $username . ' ' . $this->hmac($challenge, $password);
545 
546  // send encoded credentials
547  return $this->sendCommand('Username', base64_encode($response), 235);
548  case 'XOAUTH2':
549  //The OAuth instance must be set up prior to requesting auth.
550  if (null === $OAuth) {
551  return false;
552  }
553  $oauth = $OAuth->getOauth64();
554 
555  // Start authentication
556  if (!$this->sendCommand('AUTH', 'AUTH XOAUTH2 ' . $oauth, 235)) {
557  return false;
558  }
559  break;
560  default:
561  $this->setError("Authentication method \"$authtype\" is not supported");
562 
563  return false;
564  }
565 
566  return true;
567  }
hmac($data, $key)
Calculate an MD5 HMAC hash.
Definition: SMTP.php:579
setError($message, $detail='', $smtp_code='', $smtp_code_ex='')
Set error messages and codes.
Definition: SMTP.php:1237
edebug($str, $level=0)
Output debugging info via a user-selected method.
Definition: SMTP.php:253
sendCommand($command, $commandstring, $expect)
Send a command to an SMTP server and check its return code.
Definition: SMTP.php:933
$password
Definition: cron.php:14
$response
+ Here is the call graph for this function:

◆ client_send()

PHPMailer\PHPMailer\SMTP::client_send (   $data,
  $command = '' 
)

Send raw data to the server.

Parameters
string$dataThe data to send
string$commandOptionally, the command this is part of, used only for controlling debug output
Returns
int|bool The number of bytes sent to the server or false on error

Definition at line 1057 of file SMTP.php.

References $data, $result, and PHPMailer\PHPMailer\SMTP\edebug().

Referenced by PHPMailer\PHPMailer\SMTP\data(), and PHPMailer\PHPMailer\SMTP\sendCommand().

1058  {
1059  //If SMTP transcripts are left enabled, or debug output is posted online
1060  //it can leak credentials, so hide credentials in all but lowest level
1061  if (self::DEBUG_LOWLEVEL > $this->do_debug &&
1062  in_array($command, ['User & Password', 'Username', 'Password'], true)) {
1063  $this->edebug('CLIENT -> SERVER: [credentials hidden]', self::DEBUG_CLIENT);
1064  } else {
1065  $this->edebug('CLIENT -> SERVER: ' . $data, self::DEBUG_CLIENT);
1066  }
1067  set_error_handler([$this, 'errorHandler']);
1068  $result = fwrite($this->smtp_conn, $data);
1069  restore_error_handler();
1070 
1071  return $result;
1072  }
$result
edebug($str, $level=0)
Output debugging info via a user-selected method.
Definition: SMTP.php:253
$data
Definition: bench.php:6
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ close()

PHPMailer\PHPMailer\SMTP::close ( )

Close the socket and clean up the state of the class.

Don't use this function without first trying to use QUIT.

See also
quit()

Definition at line 638 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\edebug(), and PHPMailer\PHPMailer\SMTP\setError().

Referenced by PHPMailer\PHPMailer\SMTP\connected(), and PHPMailer\PHPMailer\SMTP\quit().

639  {
640  $this->setError('');
641  $this->server_caps = null;
642  $this->helo_rply = null;
643  if (is_resource($this->smtp_conn)) {
644  // close the connection and cleanup
645  fclose($this->smtp_conn);
646  $this->smtp_conn = null; //Makes for cleaner serialization
647  $this->edebug('Connection: closed', self::DEBUG_CONNECTION);
648  }
649  }
setError($message, $detail='', $smtp_code='', $smtp_code_ex='')
Set error messages and codes.
Definition: SMTP.php:1237
edebug($str, $level=0)
Output debugging info via a user-selected method.
Definition: SMTP.php:253
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ connect()

PHPMailer\PHPMailer\SMTP::connect (   $host,
  $port = null,
  $timeout = 30,
  $options = [] 
)

Connect to an SMTP server.

Parameters
string$hostSMTP server IP or host name
int$portThe port number to connect to
int$timeoutHow long to wait for the connection to open
array$optionsAn array of options for stream_context_create()
Returns
bool

Definition at line 312 of file SMTP.php.

References PHPMailer\PHPMailer\$options, PHPMailer\PHPMailer\SMTP\connected(), PHPMailer\PHPMailer\SMTP\edebug(), PHPMailer\PHPMailer\SMTP\get_lines(), and PHPMailer\PHPMailer\SMTP\setError().

313  {
314  static $streamok;
315  //This is enabled by default since 5.0.0 but some providers disable it
316  //Check this once and cache the result
317  if (null === $streamok) {
318  $streamok = function_exists('stream_socket_client');
319  }
320  // Clear errors to avoid confusion
321  $this->setError('');
322  // Make sure we are __not__ connected
323  if ($this->connected()) {
324  // Already connected, generate error
325  $this->setError('Already connected to a server');
326 
327  return false;
328  }
329  if (empty($port)) {
330  $port = self::DEFAULT_PORT;
331  }
332  // Connect to the SMTP server
333  $this->edebug(
334  "Connection: opening to $host:$port, timeout=$timeout, options=" .
335  (count($options) > 0 ? var_export($options, true) : 'array()'),
336  self::DEBUG_CONNECTION
337  );
338  $errno = 0;
339  $errstr = '';
340  if ($streamok) {
341  $socket_context = stream_context_create($options);
342  set_error_handler([$this, 'errorHandler']);
343  $this->smtp_conn = stream_socket_client(
344  $host . ':' . $port,
345  $errno,
346  $errstr,
347  $timeout,
348  STREAM_CLIENT_CONNECT,
349  $socket_context
350  );
351  restore_error_handler();
352  } else {
353  //Fall back to fsockopen which should work in more places, but is missing some features
354  $this->edebug(
355  'Connection: stream_socket_client not available, falling back to fsockopen',
356  self::DEBUG_CONNECTION
357  );
358  set_error_handler([$this, 'errorHandler']);
359  $this->smtp_conn = fsockopen(
360  $host,
361  $port,
362  $errno,
363  $errstr,
364  $timeout
365  );
366  restore_error_handler();
367  }
368  // Verify we connected properly
369  if (!is_resource($this->smtp_conn)) {
370  $this->setError(
371  'Failed to connect to server',
372  '',
373  (string) $errno,
374  $errstr
375  );
376  $this->edebug(
377  'SMTP ERROR: ' . $this->error['error']
378  . ": $errstr ($errno)",
379  self::DEBUG_CLIENT
380  );
381 
382  return false;
383  }
384  $this->edebug('Connection: opened', self::DEBUG_CONNECTION);
385  // SMTP server can take longer to respond, give longer timeout for first read
386  // Windows does not have support for this timeout function
387  if (strpos(PHP_OS, 'WIN') !== 0) {
388  $max = (int) ini_get('max_execution_time');
389  // Don't bother if unlimited
390  if (0 !== $max && $timeout > $max) {
391  @set_time_limit($timeout);
392  }
393  stream_set_timeout($this->smtp_conn, $timeout, 0);
394  }
395  // Get any announcement
396  $announce = $this->get_lines();
397  $this->edebug('SERVER -> CLIENT: ' . $announce, self::DEBUG_SERVER);
398 
399  return true;
400  }
get_lines()
Read the SMTP server's response.
Definition: SMTP.php:1153
setError($message, $detail='', $smtp_code='', $smtp_code_ex='')
Set error messages and codes.
Definition: SMTP.php:1237
edebug($str, $level=0)
Output debugging info via a user-selected method.
Definition: SMTP.php:253
connected()
Check connection state.
Definition: SMTP.php:611
+ Here is the call graph for this function:

◆ connected()

PHPMailer\PHPMailer\SMTP::connected ( )

Check connection state.

Returns
bool True if connected

Definition at line 611 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\close(), and PHPMailer\PHPMailer\SMTP\edebug().

Referenced by PHPMailer\PHPMailer\SMTP\connect(), and PHPMailer\PHPMailer\SMTP\sendCommand().

612  {
613  if (is_resource($this->smtp_conn)) {
614  $sock_status = stream_get_meta_data($this->smtp_conn);
615  if ($sock_status['eof']) {
616  // The socket is valid but we are not connected
617  $this->edebug(
618  'SMTP NOTICE: EOF caught while checking if connected',
619  self::DEBUG_CLIENT
620  );
621  $this->close();
622 
623  return false;
624  }
625 
626  return true; // everything looks good
627  }
628 
629  return false;
630  }
edebug($str, $level=0)
Output debugging info via a user-selected method.
Definition: SMTP.php:253
close()
Close the socket and clean up the state of the class.
Definition: SMTP.php:638
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ data()

PHPMailer\PHPMailer\SMTP::data (   $msg_data)

Send an SMTP DATA command.

Issues a data command and sends the msg_data to the server, finializing the mail transaction. $msg_data is the message that is to be send with the headers. Each header needs to be on a single line followed by a <CRLF> with the message headers and the message body being separated by an additional <CRLF>. Implements RFC 821: DATA <CRLF>.

Parameters
string$msg_dataMessage data to send
Returns
bool

Definition at line 664 of file SMTP.php.

References $result, PHPMailer\PHPMailer\SMTP\$Timelimit, PHPMailer\PHPMailer\SMTP\client_send(), PHPMailer\PHPMailer\SMTP\recordLastTransactionID(), and PHPMailer\PHPMailer\SMTP\sendCommand().

665  {
666  //This will use the standard timelimit
667  if (!$this->sendCommand('DATA', 'DATA', 354)) {
668  return false;
669  }
670 
671  /* The server is ready to accept data!
672  * According to rfc821 we should not send more than 1000 characters on a single line (including the LE)
673  * so we will break the data up into lines by \r and/or \n then if needed we will break each of those into
674  * smaller lines to fit within the limit.
675  * We will also look for lines that start with a '.' and prepend an additional '.'.
676  * NOTE: this does not count towards line-length limit.
677  */
678 
679  // Normalize line breaks before exploding
680  $lines = explode("\n", str_replace(["\r\n", "\r"], "\n", $msg_data));
681 
682  /* To distinguish between a complete RFC822 message and a plain message body, we check if the first field
683  * of the first line (':' separated) does not contain a space then it _should_ be a header and we will
684  * process all lines before a blank line as headers.
685  */
686 
687  $field = substr($lines[0], 0, strpos($lines[0], ':'));
688  $in_headers = false;
689  if (!empty($field) && strpos($field, ' ') === false) {
690  $in_headers = true;
691  }
692 
693  foreach ($lines as $line) {
694  $lines_out = [];
695  if ($in_headers && $line === '') {
696  $in_headers = false;
697  }
698  //Break this line up into several smaller lines if it's too long
699  //Micro-optimisation: isset($str[$len]) is faster than (strlen($str) > $len),
700  while (isset($line[self::MAX_LINE_LENGTH])) {
701  //Working backwards, try to find a space within the last MAX_LINE_LENGTH chars of the line to break on
702  //so as to avoid breaking in the middle of a word
703  $pos = strrpos(substr($line, 0, self::MAX_LINE_LENGTH), ' ');
704  //Deliberately matches both false and 0
705  if (!$pos) {
706  //No nice break found, add a hard break
707  $pos = self::MAX_LINE_LENGTH - 1;
708  $lines_out[] = substr($line, 0, $pos);
709  $line = substr($line, $pos);
710  } else {
711  //Break at the found point
712  $lines_out[] = substr($line, 0, $pos);
713  //Move along by the amount we dealt with
714  $line = substr($line, $pos + 1);
715  }
716  //If processing headers add a LWSP-char to the front of new line RFC822 section 3.1.1
717  if ($in_headers) {
718  $line = "\t" . $line;
719  }
720  }
721  $lines_out[] = $line;
722 
723  //Send the lines to the server
724  foreach ($lines_out as $line_out) {
725  //RFC2821 section 4.5.2
726  if (!empty($line_out) && $line_out[0] === '.') {
727  $line_out = '.' . $line_out;
728  }
729  $this->client_send($line_out . static::LE, 'DATA');
730  }
731  }
732 
733  //Message data has been sent, complete the command
734  //Increase timelimit for end of DATA command
735  $savetimelimit = $this->Timelimit;
736  $this->Timelimit *= 2;
737  $result = $this->sendCommand('DATA END', '.', 250);
738  $this->recordLastTransactionID();
739  //Restore timelimit
740  $this->Timelimit = $savetimelimit;
741 
742  return $result;
743  }
$result
recordLastTransactionID()
Extract and return the ID of the last SMTP transaction based on a list of patterns provided in SMTP::...
Definition: SMTP.php:1338
sendCommand($command, $commandstring, $expect)
Send a command to an SMTP server and check its return code.
Definition: SMTP.php:933
client_send($data, $command='')
Send raw data to the server.
Definition: SMTP.php:1057
+ Here is the call graph for this function:

◆ edebug()

PHPMailer\PHPMailer\SMTP::edebug (   $str,
  $level = 0 
)
protected

Output debugging info via a user-selected method.

Parameters
string$strDebug string to output
int$levelThe debug level of this message; see DEBUG_* constants
See also
SMTP::$Debugoutput
SMTP::$do_debug

Definition at line 253 of file SMTP.php.

References Monolog\Handler\error_log().

Referenced by PHPMailer\PHPMailer\SMTP\authenticate(), PHPMailer\PHPMailer\SMTP\client_send(), PHPMailer\PHPMailer\SMTP\close(), PHPMailer\PHPMailer\SMTP\connect(), PHPMailer\PHPMailer\SMTP\connected(), PHPMailer\PHPMailer\SMTP\errorHandler(), PHPMailer\PHPMailer\SMTP\get_lines(), PHPMailer\PHPMailer\SMTP\sendCommand(), and PHPMailer\PHPMailer\SMTP\turn().

254  {
255  if ($level > $this->do_debug) {
256  return;
257  }
258  //Is this a PSR-3 logger?
259  if ($this->Debugoutput instanceof \Psr\Log\LoggerInterface) {
260  $this->Debugoutput->debug($str);
261 
262  return;
263  }
264  //Avoid clash with built-in function names
265  if (is_callable($this->Debugoutput) && !in_array($this->Debugoutput, ['error_log', 'html', 'echo'])) {
266  call_user_func($this->Debugoutput, $str, $level);
267 
268  return;
269  }
270  switch ($this->Debugoutput) {
271  case 'error_log':
272  //Don't output, just log
273  error_log($str);
274  break;
275  case 'html':
276  //Cleans up output a bit for a better looking, HTML-safe output
277  echo gmdate('Y-m-d H:i:s'), ' ', htmlentities(
278  preg_replace('/[\r\n]+/', '', $str),
279  ENT_QUOTES,
280  'UTF-8'
281  ), "<br>\n";
282  break;
283  case 'echo':
284  default:
285  //Normalize line breaks
286  $str = preg_replace('/\r\n|\r/m', "\n", $str);
287  echo gmdate('Y-m-d H:i:s'),
288  "\t",
289  //Trim trailing space
290  trim(
291  //Indent for readability, except for trailing break
292  str_replace(
293  "\n",
294  "\n \t ",
295  trim($str)
296  )
297  ),
298  "\n";
299  }
300  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ errorHandler()

PHPMailer\PHPMailer\SMTP::errorHandler (   $errno,
  $errmsg,
  $errfile = '',
  $errline = 0 
)
protected

Reports an error number and string.

Parameters
int$errnoThe error number returned by PHP
string$errmsgThe error message returned by PHP
string$errfileThe file the error occurred in
int$errlineThe line number the error occurred on

Definition at line 1315 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\edebug(), and PHPMailer\PHPMailer\SMTP\setError().

1316  {
1317  $notice = 'Connection failed.';
1318  $this->setError(
1319  $notice,
1320  $errmsg,
1321  (string) $errno
1322  );
1323  $this->edebug(
1324  "$notice Error #$errno: $errmsg [$errfile line $errline]",
1325  self::DEBUG_CONNECTION
1326  );
1327  }
setError($message, $detail='', $smtp_code='', $smtp_code_ex='')
Set error messages and codes.
Definition: SMTP.php:1237
edebug($str, $level=0)
Output debugging info via a user-selected method.
Definition: SMTP.php:253
+ Here is the call graph for this function:

◆ get_lines()

PHPMailer\PHPMailer\SMTP::get_lines ( )
protected

Read the SMTP server's response.

Either before eof or socket timeout occurs on the operation. With SMTP we can tell if we have more lines to read if the 4th character is '-' symbol. If it is a space then we don't need to read anything else.

Returns
string

Definition at line 1153 of file SMTP.php.

References $data, $info, PHPMailer\PHPMailer\SMTP\$smtp_conn, PHPMailer\PHPMailer\SMTP\$Timelimit, and PHPMailer\PHPMailer\SMTP\edebug().

Referenced by PHPMailer\PHPMailer\SMTP\connect(), and PHPMailer\PHPMailer\SMTP\sendCommand().

1154  {
1155  // If the connection is bad, give up straight away
1156  if (!is_resource($this->smtp_conn)) {
1157  return '';
1158  }
1159  $data = '';
1160  $endtime = 0;
1161  stream_set_timeout($this->smtp_conn, $this->Timeout);
1162  if ($this->Timelimit > 0) {
1163  $endtime = time() + $this->Timelimit;
1164  }
1165  $selR = [$this->smtp_conn];
1166  $selW = null;
1167  while (is_resource($this->smtp_conn) && !feof($this->smtp_conn)) {
1168  //Must pass vars in here as params are by reference
1169  if (!stream_select($selR, $selW, $selW, $this->Timelimit)) {
1170  $this->edebug(
1171  'SMTP -> get_lines(): select timed-out in (' . $this->Timelimit . ' sec)',
1172  self::DEBUG_LOWLEVEL
1173  );
1174  break;
1175  }
1176  //Deliberate noise suppression - errors are handled afterwards
1177  $str = @fgets($this->smtp_conn, self::MAX_REPLY_LENGTH);
1178  $this->edebug('SMTP INBOUND: "' . trim($str) . '"', self::DEBUG_LOWLEVEL);
1179  $data .= $str;
1180  // If response is only 3 chars (not valid, but RFC5321 S4.2 says it must be handled),
1181  // or 4th character is a space or a line break char, we are done reading, break the loop.
1182  // String array access is a significant micro-optimisation over strlen
1183  if (!isset($str[3]) || $str[3] === ' ' || $str[3] === "\r" || $str[3] === "\n") {
1184  break;
1185  }
1186  // Timed-out? Log and break
1187  $info = stream_get_meta_data($this->smtp_conn);
1188  if ($info['timed_out']) {
1189  $this->edebug(
1190  'SMTP -> get_lines(): stream timed-out (' . $this->Timeout . ' sec)',
1191  self::DEBUG_LOWLEVEL
1192  );
1193  break;
1194  }
1195  // Now check if reads took too long
1196  if ($endtime && time() > $endtime) {
1197  $this->edebug(
1198  'SMTP -> get_lines(): timelimit reached (' .
1199  $this->Timelimit . ' sec)',
1200  self::DEBUG_LOWLEVEL
1201  );
1202  break;
1203  }
1204  }
1205 
1206  return $data;
1207  }
edebug($str, $level=0)
Output debugging info via a user-selected method.
Definition: SMTP.php:253
$info
Definition: index.php:5
$data
Definition: bench.php:6
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDebugLevel()

PHPMailer\PHPMailer\SMTP::getDebugLevel ( )

Get debug output level.

Returns
int

Definition at line 1282 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\$do_debug.

1283  {
1284  return $this->do_debug;
1285  }

◆ getDebugOutput()

PHPMailer\PHPMailer\SMTP::getDebugOutput ( )

Get debug output method.

Returns
string

Definition at line 1262 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\$Debugoutput.

1263  {
1264  return $this->Debugoutput;
1265  }

◆ getError()

PHPMailer\PHPMailer\SMTP::getError ( )

Get the latest error.

Returns
array

Definition at line 1079 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\$error.

1080  {
1081  return $this->error;
1082  }

◆ getLastReply()

PHPMailer\PHPMailer\SMTP::getLastReply ( )

Get the last reply from the server.

Returns
string

Definition at line 1139 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\$last_reply.

Referenced by PHPMailer\PHPMailer\SMTP\recordLastTransactionID().

1140  {
1141  return $this->last_reply;
1142  }
+ Here is the caller graph for this function:

◆ getLastTransactionID()

PHPMailer\PHPMailer\SMTP::getLastTransactionID ( )

Get the queue/transaction ID of the last SMTP transaction If no reply has been received yet, it will return null.

If no pattern was matched, it will return false.

Returns
bool|string|null
See also
recordLastTransactionID()

Definition at line 1367 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\$last_smtp_transaction_id.

1368  {
1370  }

◆ getServerExt()

PHPMailer\PHPMailer\SMTP::getServerExt (   $name)

Get metadata about the SMTP server from its HELO/EHLO response.

The method works in three ways, dependent on argument value and current state:

  1. HELO/EHLO has not been sent - returns null and populates $this->error.
  2. HELO has been sent - $name == 'HELO': returns server name $name == 'EHLO': returns boolean false $name == any other string: returns null and populates $this->error
  3. EHLO has been sent - $name == 'HELO'|'EHLO': returns the server name $name == any other string: if extension $name exists, returns True or its options (e.g. AUTH mechanisms supported). Otherwise returns False.
Parameters
string$nameName of SMTP extension or 'HELO'|'EHLO'
Returns
string|bool|null

Definition at line 1111 of file SMTP.php.

References $name, and PHPMailer\PHPMailer\SMTP\setError().

1112  {
1113  if (!$this->server_caps) {
1114  $this->setError('No HELO/EHLO was sent');
1115 
1116  return;
1117  }
1118 
1119  if (!array_key_exists($name, $this->server_caps)) {
1120  if ('HELO' === $name) {
1121  return $this->server_caps['EHLO'];
1122  }
1123  if ('EHLO' === $name || array_key_exists('EHLO', $this->server_caps)) {
1124  return false;
1125  }
1126  $this->setError('HELO handshake was used; No information about server extensions available');
1127 
1128  return;
1129  }
1130 
1131  return $this->server_caps[$name];
1132  }
setError($message, $detail='', $smtp_code='', $smtp_code_ex='')
Set error messages and codes.
Definition: SMTP.php:1237
+ Here is the call graph for this function:

◆ getServerExtList()

PHPMailer\PHPMailer\SMTP::getServerExtList ( )

Get SMTP extensions available on the server.

Returns
array|null

Definition at line 1089 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\$server_caps.

1090  {
1091  return $this->server_caps;
1092  }

◆ getTimeout()

PHPMailer\PHPMailer\SMTP::getTimeout ( )

Get SMTP timeout.

Returns
int

Definition at line 1302 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\$Timeout.

1303  {
1304  return $this->Timeout;
1305  }

◆ getVerp()

PHPMailer\PHPMailer\SMTP::getVerp ( )

Get VERP address generation mode.

Returns
bool

Definition at line 1224 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\$do_verp.

1225  {
1226  return $this->do_verp;
1227  }

◆ hello()

PHPMailer\PHPMailer\SMTP::hello (   $host = '')

Send an SMTP HELO or EHLO command.

Used to identify the sending server to the receiving server. This makes sure that client and server are in a known state. Implements RFC 821: HELO <SP> <domain> <CRLF> and RFC 2821 EHLO.

Parameters
string$hostThe host name or IP to connect to
Returns
bool

Definition at line 756 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\sendHello().

757  {
758  //Try extended hello first (RFC 2821)
759  return $this->sendHello('EHLO', $host) or $this->sendHello('HELO', $host);
760  }
sendHello($hello, $host)
Send an SMTP HELO or EHLO command.
Definition: SMTP.php:773
+ Here is the call graph for this function:

◆ hmac()

PHPMailer\PHPMailer\SMTP::hmac (   $data,
  $key 
)
protected

Calculate an MD5 HMAC hash.

Works like hash_hmac('md5', $data, $key) in case that function is not available.

Parameters
string$dataThe data to hash
string$keyThe key to hash with
Returns
string

Definition at line 579 of file SMTP.php.

References $data, and $key.

Referenced by PHPMailer\PHPMailer\SMTP\authenticate().

580  {
581  if (function_exists('hash_hmac')) {
582  return hash_hmac('md5', $data, $key);
583  }
584 
585  // The following borrowed from
586  // http://php.net/manual/en/function.mhash.php#27225
587 
588  // RFC 2104 HMAC implementation for php.
589  // Creates an md5 HMAC.
590  // Eliminates the need to install mhash to compute a HMAC
591  // by Lance Rushing
592 
593  $bytelen = 64; // byte length for md5
594  if (strlen($key) > $bytelen) {
595  $key = pack('H*', md5($key));
596  }
597  $key = str_pad($key, $bytelen, chr(0x00));
598  $ipad = str_pad('', $bytelen, chr(0x36));
599  $opad = str_pad('', $bytelen, chr(0x5c));
600  $k_ipad = $key ^ $ipad;
601  $k_opad = $key ^ $opad;
602 
603  return md5($k_opad . pack('H*', md5($k_ipad . $data)));
604  }
$key
Definition: croninfo.php:18
$data
Definition: bench.php:6
+ Here is the caller graph for this function:

◆ mail()

PHPMailer\PHPMailer\SMTP::mail (   $from)

Send an SMTP MAIL command.

Starts a mail transaction from the email address specified in $from. Returns true if successful or false otherwise. If True the mail transaction is started and then one or more recipient commands may be called followed by a data command. Implements RFC 821: MAIL <SP> FROM:<reverse-path> <CRLF>.

Parameters
string$fromSource address of this message
Returns
bool

Definition at line 840 of file SMTP.php.

References $from, and PHPMailer\PHPMailer\SMTP\sendCommand().

841  {
842  $useVerp = ($this->do_verp ? ' XVERP' : '');
843 
844  return $this->sendCommand(
845  'MAIL FROM',
846  'MAIL FROM:<' . $from . '>' . $useVerp,
847  250
848  );
849  }
$from
sendCommand($command, $commandstring, $expect)
Send a command to an SMTP server and check its return code.
Definition: SMTP.php:933
+ Here is the call graph for this function:

◆ noop()

PHPMailer\PHPMailer\SMTP::noop ( )

Send an SMTP NOOP command.

Used to keep keep-alives alive, doesn't actually do anything.

Returns
bool

Definition at line 1027 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\sendCommand().

1028  {
1029  return $this->sendCommand('NOOP', 'NOOP', 250);
1030  }
sendCommand($command, $commandstring, $expect)
Send a command to an SMTP server and check its return code.
Definition: SMTP.php:933
+ Here is the call graph for this function:

◆ parseHelloFields()

PHPMailer\PHPMailer\SMTP::parseHelloFields (   $type)
protected

Parse a reply to HELO/EHLO command to discover server extensions.

In case of HELO, the only parameter that can be discovered is a server name.

Parameters
string$typeHELO or EHLO

Definition at line 792 of file SMTP.php.

References $n, $name, $s, and $type.

Referenced by PHPMailer\PHPMailer\SMTP\sendHello().

793  {
794  $this->server_caps = [];
795  $lines = explode("\n", $this->helo_rply);
796 
797  foreach ($lines as $n => $s) {
798  //First 4 chars contain response code followed by - or space
799  $s = trim(substr($s, 4));
800  if (empty($s)) {
801  continue;
802  }
803  $fields = explode(' ', $s);
804  if (!empty($fields)) {
805  if (!$n) {
806  $name = $type;
807  $fields = $fields[0];
808  } else {
809  $name = array_shift($fields);
810  switch ($name) {
811  case 'SIZE':
812  $fields = ($fields ? $fields[0] : 0);
813  break;
814  case 'AUTH':
815  if (!is_array($fields)) {
816  $fields = [];
817  }
818  break;
819  default:
820  $fields = true;
821  }
822  }
823  $this->server_caps[$name] = $fields;
824  }
825  }
826  }
$type
$s
Definition: pwgen.php:45
$n
Definition: RandomTest.php:85
+ Here is the caller graph for this function:

◆ quit()

PHPMailer\PHPMailer\SMTP::quit (   $close_on_error = true)

Send an SMTP QUIT command.

Closes the socket if there is no error or the $close_on_error argument is true. Implements from RFC 821: QUIT <CRLF>.

Parameters
bool$close_on_errorShould the connection close if an error occurs?
Returns
bool

Definition at line 860 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\$error, PHPMailer\PHPMailer\SMTP\close(), and PHPMailer\PHPMailer\SMTP\sendCommand().

861  {
862  $noerror = $this->sendCommand('QUIT', 'QUIT', 221);
863  $err = $this->error; //Save any error
864  if ($noerror || $close_on_error) {
865  $this->close();
866  $this->error = $err; //Restore any error from the quit command
867  }
868 
869  return $noerror;
870  }
close()
Close the socket and clean up the state of the class.
Definition: SMTP.php:638
sendCommand($command, $commandstring, $expect)
Send a command to an SMTP server and check its return code.
Definition: SMTP.php:933
+ Here is the call graph for this function:

◆ recipient()

PHPMailer\PHPMailer\SMTP::recipient (   $address,
  $dsn = '' 
)

Send an SMTP RCPT command.

Sets the TO argument to $toaddr. Returns true if the recipient was accepted false if it was rejected. Implements from RFC 821: RCPT <SP> TO:<forward-path> <CRLF>.

Parameters
string$addressThe address the message is being sent to
string$dsnComma separated list of DSN notifications. NEVER, SUCCESS, FAILURE or DELAY. If you specify NEVER all other notifications are ignored.
Returns
bool

Definition at line 884 of file SMTP.php.

References $dsn, and PHPMailer\PHPMailer\SMTP\sendCommand().

885  {
886  if (empty($dsn)) {
887  $rcpt = 'RCPT TO:<' . $address . '>';
888  } else {
889  $dsn = strtoupper($dsn);
890  $notify = [];
891 
892  if (strpos($dsn, 'NEVER') !== false) {
893  $notify[] = 'NEVER';
894  } else {
895  foreach (['SUCCESS', 'FAILURE', 'DELAY'] as $value) {
896  if (strpos($dsn, $value) !== false) {
897  $notify[] = $value;
898  }
899  }
900  }
901 
902  $rcpt = 'RCPT TO:<' . $address . '> NOTIFY=' . implode(',', $notify);
903  }
904 
905  return $this->sendCommand(
906  'RCPT TO',
907  $rcpt,
908  [250, 251]
909  );
910  }
foreach($paths as $path) $dsn
Definition: migrateto20.php:56
sendCommand($command, $commandstring, $expect)
Send a command to an SMTP server and check its return code.
Definition: SMTP.php:933
+ Here is the call graph for this function:

◆ recordLastTransactionID()

PHPMailer\PHPMailer\SMTP::recordLastTransactionID ( )
protected

Extract and return the ID of the last SMTP transaction based on a list of patterns provided in SMTP::$smtp_transaction_id_patterns.

Relies on the host providing the ID in response to a DATA command. If no reply has been received yet, it will return null. If no pattern was matched, it will return false.

Returns
bool|string|null

Definition at line 1338 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\$last_smtp_transaction_id, and PHPMailer\PHPMailer\SMTP\getLastReply().

Referenced by PHPMailer\PHPMailer\SMTP\data().

1339  {
1340  $reply = $this->getLastReply();
1341 
1342  if (empty($reply)) {
1343  $this->last_smtp_transaction_id = null;
1344  } else {
1345  $this->last_smtp_transaction_id = false;
1346  foreach ($this->smtp_transaction_id_patterns as $smtp_transaction_id_pattern) {
1347  $matches = [];
1348  if (preg_match($smtp_transaction_id_pattern, $reply, $matches)) {
1349  $this->last_smtp_transaction_id = trim($matches[1]);
1350  break;
1351  }
1352  }
1353  }
1354 
1356  }
getLastReply()
Get the last reply from the server.
Definition: SMTP.php:1139
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset()

PHPMailer\PHPMailer\SMTP::reset ( )

Send an SMTP RSET command.

Abort any transaction that is currently in progress. Implements RFC 821: RSET <CRLF>.

Returns
bool True on success

Definition at line 919 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\sendCommand().

920  {
921  return $this->sendCommand('RSET', 'RSET', 250);
922  }
sendCommand($command, $commandstring, $expect)
Send a command to an SMTP server and check its return code.
Definition: SMTP.php:933
+ Here is the call graph for this function:

◆ sendAndMail()

PHPMailer\PHPMailer\SMTP::sendAndMail (   $from)

Send an SMTP SAML command.

Starts a mail transaction from the email address specified in $from. Returns true if successful or false otherwise. If True the mail transaction is started and then one or more recipient commands may be called followed by a data command. This command will send the message to the users terminal if they are logged in and send them an email. Implements RFC 821: SAML <SP> FROM:<reverse-path> <CRLF>.

Parameters
string$fromThe address the message is from
Returns
bool

Definition at line 1004 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\sendCommand().

1005  {
1006  return $this->sendCommand('SAML', "SAML FROM:$from", 250);
1007  }
sendCommand($command, $commandstring, $expect)
Send a command to an SMTP server and check its return code.
Definition: SMTP.php:933
+ Here is the call graph for this function:

◆ sendCommand()

PHPMailer\PHPMailer\SMTP::sendCommand (   $command,
  $commandstring,
  $expect 
)
protected

Send a command to an SMTP server and check its return code.

Parameters
string$commandThe command name - not sent to the server
string$commandstringThe actual command to send
int | array$expectOne or more expected integer success codes
Returns
bool True on success

Definition at line 933 of file SMTP.php.

References $code, PHPMailer\PHPMailer\SMTP\client_send(), PHPMailer\PHPMailer\SMTP\connected(), PHPMailer\PHPMailer\SMTP\edebug(), PHPMailer\PHPMailer\SMTP\get_lines(), and PHPMailer\PHPMailer\SMTP\setError().

Referenced by PHPMailer\PHPMailer\SMTP\authenticate(), PHPMailer\PHPMailer\SMTP\data(), PHPMailer\PHPMailer\SMTP\mail(), PHPMailer\PHPMailer\SMTP\noop(), PHPMailer\PHPMailer\SMTP\quit(), PHPMailer\PHPMailer\SMTP\recipient(), PHPMailer\PHPMailer\SMTP\reset(), PHPMailer\PHPMailer\SMTP\sendAndMail(), PHPMailer\PHPMailer\SMTP\sendHello(), PHPMailer\PHPMailer\SMTP\startTLS(), and PHPMailer\PHPMailer\SMTP\verify().

934  {
935  if (!$this->connected()) {
936  $this->setError("Called $command without being connected");
937 
938  return false;
939  }
940  //Reject line breaks in all commands
941  if ((strpos($commandstring, "\n") !== false) || (strpos($commandstring, "\r") !== false)) {
942  $this->setError("Command '$command' contained line breaks");
943 
944  return false;
945  }
946  $this->client_send($commandstring . static::LE, $command);
947 
948  $this->last_reply = $this->get_lines();
949  // Fetch SMTP code and possible error code explanation
950  $matches = [];
951  if (preg_match('/^([\d]{3})[ -](?:([\d]\\.[\d]\\.[\d]{1,2}) )?/', $this->last_reply, $matches)) {
952  $code = (int) $matches[1];
953  $code_ex = (count($matches) > 2 ? $matches[2] : null);
954  // Cut off error code from each response line
955  $detail = preg_replace(
956  "/{$code}[ -]" .
957  ($code_ex ? str_replace('.', '\\.', $code_ex) . ' ' : '') . '/m',
958  '',
959  $this->last_reply
960  );
961  } else {
962  // Fall back to simple parsing if regex fails
963  $code = (int) substr($this->last_reply, 0, 3);
964  $code_ex = null;
965  $detail = substr($this->last_reply, 4);
966  }
967 
968  $this->edebug('SERVER -> CLIENT: ' . $this->last_reply, self::DEBUG_SERVER);
969 
970  if (!in_array($code, (array) $expect, true)) {
971  $this->setError(
972  "$command command failed",
973  $detail,
974  $code,
975  $code_ex
976  );
977  $this->edebug(
978  'SMTP ERROR: ' . $this->error['error'] . ': ' . $this->last_reply,
979  self::DEBUG_CLIENT
980  );
981 
982  return false;
983  }
984 
985  $this->setError('');
986 
987  return true;
988  }
$code
Definition: example_050.php:99
get_lines()
Read the SMTP server&#39;s response.
Definition: SMTP.php:1153
setError($message, $detail='', $smtp_code='', $smtp_code_ex='')
Set error messages and codes.
Definition: SMTP.php:1237
edebug($str, $level=0)
Output debugging info via a user-selected method.
Definition: SMTP.php:253
client_send($data, $command='')
Send raw data to the server.
Definition: SMTP.php:1057
connected()
Check connection state.
Definition: SMTP.php:611
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendHello()

PHPMailer\PHPMailer\SMTP::sendHello (   $hello,
  $host 
)
protected

Send an SMTP HELO or EHLO command.

Low-level implementation used by hello().

Parameters
string$helloThe HELO string
string$hostThe hostname to say we are
Returns
bool
See also
hello()

Definition at line 773 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\$last_reply, PHPMailer\PHPMailer\SMTP\parseHelloFields(), and PHPMailer\PHPMailer\SMTP\sendCommand().

Referenced by PHPMailer\PHPMailer\SMTP\hello().

774  {
775  $noerror = $this->sendCommand($hello, $hello . ' ' . $host, 250);
776  $this->helo_rply = $this->last_reply;
777  if ($noerror) {
778  $this->parseHelloFields($hello);
779  } else {
780  $this->server_caps = null;
781  }
782 
783  return $noerror;
784  }
parseHelloFields($type)
Parse a reply to HELO/EHLO command to discover server extensions.
Definition: SMTP.php:792
sendCommand($command, $commandstring, $expect)
Send a command to an SMTP server and check its return code.
Definition: SMTP.php:933
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDebugLevel()

PHPMailer\PHPMailer\SMTP::setDebugLevel (   $level = 0)

Set debug output level.

Parameters
int$level

Definition at line 1272 of file SMTP.php.

1273  {
1274  $this->do_debug = $level;
1275  }

◆ setDebugOutput()

PHPMailer\PHPMailer\SMTP::setDebugOutput (   $method = 'echo')

Set debug output method.

Parameters
string | callable$methodThe name of the mechanism to use for debugging output, or a callable to handle it

Definition at line 1252 of file SMTP.php.

1253  {
1254  $this->Debugoutput = $method;
1255  }

◆ setError()

PHPMailer\PHPMailer\SMTP::setError (   $message,
  $detail = '',
  $smtp_code = '',
  $smtp_code_ex = '' 
)
protected

Set error messages and codes.

Parameters
string$messageThe error message
string$detailFurther detail on the error
string$smtp_codeAn associated SMTP error code
string$smtp_code_exExtended SMTP code

Definition at line 1237 of file SMTP.php.

References $message.

Referenced by PHPMailer\PHPMailer\SMTP\authenticate(), PHPMailer\PHPMailer\SMTP\close(), PHPMailer\PHPMailer\SMTP\connect(), PHPMailer\PHPMailer\SMTP\errorHandler(), PHPMailer\PHPMailer\SMTP\getServerExt(), PHPMailer\PHPMailer\SMTP\sendCommand(), and PHPMailer\PHPMailer\SMTP\turn().

1238  {
1239  $this->error = [
1240  'error' => $message,
1241  'detail' => $detail,
1242  'smtp_code' => $smtp_code,
1243  'smtp_code_ex' => $smtp_code_ex,
1244  ];
1245  }
catch(Exception $e) $message
+ Here is the caller graph for this function:

◆ setTimeout()

PHPMailer\PHPMailer\SMTP::setTimeout (   $timeout = 0)

Set SMTP timeout.

Parameters
int$timeoutThe timeout duration in seconds

Definition at line 1292 of file SMTP.php.

1293  {
1294  $this->Timeout = $timeout;
1295  }

◆ setVerp()

PHPMailer\PHPMailer\SMTP::setVerp (   $enabled = false)

Enable or disable VERP address generation.

Parameters
bool$enabled

Definition at line 1214 of file SMTP.php.

1215  {
1216  $this->do_verp = $enabled;
1217  }

◆ startTLS()

PHPMailer\PHPMailer\SMTP::startTLS ( )

Initiate a TLS (encrypted) session.

Returns
bool

Definition at line 407 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\sendCommand().

408  {
409  if (!$this->sendCommand('STARTTLS', 'STARTTLS', 220)) {
410  return false;
411  }
412 
413  //Allow the best TLS version(s) we can
414  $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT;
415 
416  //PHP 5.6.7 dropped inclusion of TLS 1.1 and 1.2 in STREAM_CRYPTO_METHOD_TLS_CLIENT
417  //so add them back in manually if we can
418  if (defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
419  $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
420  $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
421  }
422 
423  // Begin encrypted connection
424  set_error_handler([$this, 'errorHandler']);
425  $crypto_ok = stream_socket_enable_crypto(
426  $this->smtp_conn,
427  true,
428  $crypto_method
429  );
430  restore_error_handler();
431 
432  return (bool) $crypto_ok;
433  }
sendCommand($command, $commandstring, $expect)
Send a command to an SMTP server and check its return code.
Definition: SMTP.php:933
+ Here is the call graph for this function:

◆ turn()

PHPMailer\PHPMailer\SMTP::turn ( )

Send an SMTP TURN command.

This is an optional command for SMTP that this class does not support. This method is here to make the RFC821 Definition complete for this class and may be implemented in future. Implements from RFC 821: TURN <CRLF>.

Returns
bool

Definition at line 1041 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\edebug(), and PHPMailer\PHPMailer\SMTP\setError().

1042  {
1043  $this->setError('The SMTP TURN command is not implemented');
1044  $this->edebug('SMTP NOTICE: ' . $this->error['error'], self::DEBUG_CLIENT);
1045 
1046  return false;
1047  }
setError($message, $detail='', $smtp_code='', $smtp_code_ex='')
Set error messages and codes.
Definition: SMTP.php:1237
edebug($str, $level=0)
Output debugging info via a user-selected method.
Definition: SMTP.php:253
+ Here is the call graph for this function:

◆ verify()

PHPMailer\PHPMailer\SMTP::verify (   $name)

Send an SMTP VRFY command.

Parameters
string$nameThe name to verify
Returns
bool

Definition at line 1016 of file SMTP.php.

References PHPMailer\PHPMailer\SMTP\sendCommand().

1017  {
1018  return $this->sendCommand('VRFY', "VRFY $name", [250, 251]);
1019  }
sendCommand($command, $commandstring, $expect)
Send a command to an SMTP server and check its return code.
Definition: SMTP.php:933
+ Here is the call graph for this function:

Field Documentation

◆ $Debugoutput

PHPMailer\PHPMailer\SMTP::$Debugoutput = 'echo'

Definition at line 142 of file SMTP.php.

Referenced by PHPMailer\PHPMailer\SMTP\getDebugOutput().

◆ $do_debug

PHPMailer\PHPMailer\SMTP::$do_debug = self::DEBUG_OFF

Definition at line 119 of file SMTP.php.

Referenced by PHPMailer\PHPMailer\SMTP\getDebugLevel().

◆ $do_verp

PHPMailer\PHPMailer\SMTP::$do_verp = false

Definition at line 152 of file SMTP.php.

Referenced by PHPMailer\PHPMailer\SMTP\getVerp().

◆ $error

PHPMailer\PHPMailer\SMTP::$error
protected
Initial value:
= [
'error' => ''

Definition at line 210 of file SMTP.php.

Referenced by PHPMailer\PHPMailer\SMTP\getError(), and PHPMailer\PHPMailer\SMTP\quit().

◆ $helo_rply

PHPMailer\PHPMailer\SMTP::$helo_rply
protected

Definition at line 223 of file SMTP.php.

◆ $last_reply

PHPMailer\PHPMailer\SMTP::$last_reply = ''
protected

◆ $last_smtp_transaction_id

PHPMailer\PHPMailer\SMTP::$last_smtp_transaction_id
protected

◆ $server_caps

PHPMailer\PHPMailer\SMTP::$server_caps
protected

Definition at line 235 of file SMTP.php.

Referenced by PHPMailer\PHPMailer\SMTP\getServerExtList().

◆ $smtp_conn

PHPMailer\PHPMailer\SMTP::$smtp_conn
protected

Definition at line 203 of file SMTP.php.

Referenced by PHPMailer\PHPMailer\SMTP\get_lines().

◆ $smtp_transaction_id_patterns

PHPMailer\PHPMailer\SMTP::$smtp_transaction_id_patterns
protected
Initial value:
= [
'exim' => '/[\d]{3} OK id=(.*)/'

Definition at line 180 of file SMTP.php.

◆ $Timelimit

PHPMailer\PHPMailer\SMTP::$Timelimit = 300

Definition at line 171 of file SMTP.php.

Referenced by PHPMailer\PHPMailer\SMTP\data(), and PHPMailer\PHPMailer\SMTP\get_lines().

◆ $Timeout

PHPMailer\PHPMailer\SMTP::$Timeout = 300

Definition at line 163 of file SMTP.php.

Referenced by PHPMailer\PHPMailer\SMTP\getTimeout().

◆ DEBUG_CLIENT

const PHPMailer\PHPMailer\SMTP::DEBUG_CLIENT = 1

Definition at line 85 of file SMTP.php.

◆ DEBUG_CONNECTION

const PHPMailer\PHPMailer\SMTP::DEBUG_CONNECTION = 3

Definition at line 99 of file SMTP.php.

◆ DEBUG_LOWLEVEL

const PHPMailer\PHPMailer\SMTP::DEBUG_LOWLEVEL = 4

Definition at line 106 of file SMTP.php.

◆ DEBUG_OFF

const PHPMailer\PHPMailer\SMTP::DEBUG_OFF = 0

Definition at line 78 of file SMTP.php.

◆ DEBUG_SERVER

const PHPMailer\PHPMailer\SMTP::DEBUG_SERVER = 2

Definition at line 92 of file SMTP.php.

◆ DEFAULT_PORT

const PHPMailer\PHPMailer\SMTP::DEFAULT_PORT = 25

Definition at line 51 of file SMTP.php.

◆ LE

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

Definition at line 44 of file SMTP.php.

◆ MAX_LINE_LENGTH

const PHPMailer\PHPMailer\SMTP::MAX_LINE_LENGTH = 998

Definition at line 61 of file SMTP.php.

◆ MAX_REPLY_LENGTH

const PHPMailer\PHPMailer\SMTP::MAX_REPLY_LENGTH = 512

Definition at line 71 of file SMTP.php.

◆ VERSION

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

Definition at line 37 of file SMTP.php.


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