Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Zend_Mail_Protocol_Smtp Class Reference
Inheritance diagram for Zend_Mail_Protocol_Smtp:
Zend_Mail_Protocol_Abstract Zend_Mail_Protocol_Smtp_Auth_Crammd5 Zend_Mail_Protocol_Smtp_Auth_Login Zend_Mail_Protocol_Smtp_Auth_Plain

Public Member Functions

 __construct ($host='127.0.0.1', $port=null, array $config=array())
 
 connect ()
 
 helo ($host='127.0.0.1')
 
 mail ($from)
 
 rcpt ($to)
 
 data ($data)
 
 rset ()
 
 noop ()
 
 vrfy ($user)
 
 quit ()
 
 auth ()
 
 disconnect ()
 
- Public Member Functions inherited from Zend_Mail_Protocol_Abstract
 __construct ($host='127.0.0.1', $port=null)
 
 __destruct ()
 
 setMaximumLog ($maximumLog)
 
 getMaximumLog ()
 
 connect ()
 
 getRequest ()
 
 getResponse ()
 
 getLog ()
 
 resetLog ()
 

Protected Member Functions

 _ehlo ($host)
 
 _startSession ()
 
 _stopSession ()
 
- Protected Member Functions inherited from Zend_Mail_Protocol_Abstract
 _addLog ($value)
 
 _connect ($remote)
 
 _disconnect ()
 
 _send ($request)
 
 _receive ($timeout=null)
 
 _expect ($code, $timeout=null)
 
 _setStreamTimeout ($timeout)
 

Protected Attributes

 $_transport = 'tcp'
 
 $_secure
 
 $_sess = false
 
 $_helo = false
 
 $_auth = false
 
 $_mail = false
 
 $_rcpt = false
 
 $_data = null
 
- Protected Attributes inherited from Zend_Mail_Protocol_Abstract
 $_maximumLog = 64
 
 $_host
 
 $_port
 
 $_validHost
 
 $_socket
 
 $_request
 
 $_response
 
 $_template = '%d%s'
 

Additional Inherited Members

- Data Fields inherited from Zend_Mail_Protocol_Abstract
const EOL = "\r\n"
 
const TIMEOUT_CONNECTION = 30
 

Detailed Description

Definition at line 48 of file Smtp.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $host = '127.0.0.1',
  $port = null,
array  $config = array() 
)

Constructor.

Parameters
string$host
integer$port
array$config
Returns
void
Exceptions
Zend_Mail_Protocol_Exception
See also
Zend_Mail_Protocol_Exception

Definition at line 123 of file Smtp.php.

124  {
125  if (isset($config['ssl'])) {
126  switch (strtolower($config['ssl'])) {
127  case 'tls':
128  $this->_secure = 'tls';
129  break;
130 
131  case 'ssl':
132  $this->_transport = 'ssl';
133  $this->_secure = 'ssl';
134  if ($port == null) {
135  $port = 465;
136  }
137  break;
138 
139  default:
143  #require_once 'Zend/Mail/Protocol/Exception.php';
144  throw new Zend_Mail_Protocol_Exception($config['ssl'] . ' is unsupported SSL type');
145  break;
146  }
147  }
148 
149  // If no port has been specified then check the master PHP ini file. Defaults to 25 if the ini setting is null.
150  if ($port == null) {
151  if (($port = ini_get('smtp_port')) == '') {
152  $port = 25;
153  }
154  }
155 
156  parent::__construct($host, $port);
157  }
$config
Definition: fraud_order.php:17

Member Function Documentation

◆ _ehlo()

_ehlo (   $host)
protected

Send EHLO or HELO depending on capabilities of smtp host

Parameters
string$hostThe client hostname or IP address (default: 127.0.0.1)
Exceptions
Zend_Mail_Protocol_Exception
Returns
void

Definition at line 229 of file Smtp.php.

230  {
231  // Support for older, less-compliant remote servers. Tries multiple attempts of EHLO or HELO.
232  try {
233  $this->_send('EHLO ' . $host);
234  $this->_expect(250, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
235  } catch (Zend_Mail_Protocol_Exception $e) {
236  $this->_send('HELO ' . $host);
237  $this->_expect(250, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
238  } catch (Zend_Mail_Protocol_Exception $e) {
239  throw $e;
240  }
241  }
_expect($code, $timeout=null)
Definition: Abstract.php:402

◆ _startSession()

_startSession ( )
protected

Start mail session

Returns
void

Definition at line 429 of file Smtp.php.

430  {
431  $this->_sess = true;
432  }

◆ _stopSession()

_stopSession ( )
protected

Stop mail session

Returns
void

Definition at line 440 of file Smtp.php.

441  {
442  $this->_sess = false;
443  }

◆ auth()

auth ( )

Default authentication method

This default method is implemented by AUTH adapters to properly authenticate to a remote host.

Exceptions
Zend_Mail_Protocol_Exception
Returns
void
See also
Zend_Mail_Protocol_Exception

Definition at line 401 of file Smtp.php.

402  {
403  if ($this->_auth === true) {
407  #require_once 'Zend/Mail/Protocol/Exception.php';
408  throw new Zend_Mail_Protocol_Exception('Already authenticated for this session');
409  }
410  }

◆ connect()

connect ( )

Connect to the server with the parameters given in the constructor.

Returns
boolean

Definition at line 165 of file Smtp.php.

166  {
167  return $this->_connect($this->_transport . '://' . $this->_host . ':'. $this->_port);
168  }

◆ data()

data (   $data)

Issues DATA command

Parameters
string$data
Exceptions
Zend_Mail_Protocol_Exception
Returns
void
See also
Zend_Mail_Protocol_Exception

Definition at line 302 of file Smtp.php.

303  {
304  // Ensure recipients have been set
305  if ($this->_rcpt !== true) {
309  #require_once 'Zend/Mail/Protocol/Exception.php';
310  throw new Zend_Mail_Protocol_Exception('No recipient forward path has been supplied');
311  }
312 
313  $this->_send('DATA');
314  $this->_expect(354, 120); // Timeout set for 2 minutes as per RFC 2821 4.5.3.2
315 
316  foreach (explode(Zend_Mime::LINEEND, $data) as $line) {
317  if (strpos($line, '.') === 0) {
318  // Escape lines prefixed with a '.'
319  $line = '.' . $line;
320  }
321  $this->_send($line);
322  }
323 
324  $this->_send('.');
325  $this->_expect(250, 600); // Timeout set for 10 minutes as per RFC 2821 4.5.3.2
326  $this->_data = true;
327  }
_expect($code, $timeout=null)
Definition: Abstract.php:402
const LINEEND
Definition: Mime.php:42

◆ disconnect()

disconnect ( )

Closes connection

Returns
void

Definition at line 418 of file Smtp.php.

419  {
420  $this->_disconnect();
421  }

◆ helo()

helo (   $host = '127.0.0.1')

Initiate HELO/EHLO sequence and set flag to indicate valid smtp session

Parameters
string$hostThe client hostname or IP address (default: 127.0.0.1)
Exceptions
Zend_Mail_Protocol_Exception
Returns
void
See also
Zend_Mail_Protocol_Exception
Zend_Mail_Protocol_Exception
Zend_Mail_Protocol_Exception

Definition at line 178 of file Smtp.php.

179  {
180  // Respect RFC 2821 and disallow HELO attempts if session is already initiated.
181  if ($this->_sess === true) {
185  #require_once 'Zend/Mail/Protocol/Exception.php';
186  throw new Zend_Mail_Protocol_Exception('Cannot issue HELO to existing session');
187  }
188 
189  // Validate client hostname
190  if (!$this->_validHost->isValid($host)) {
194  #require_once 'Zend/Mail/Protocol/Exception.php';
195  throw new Zend_Mail_Protocol_Exception(join(', ', $this->_validHost->getMessages()));
196  }
197 
198  // Initiate helo sequence
199  $this->_expect(220, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
200  $this->_ehlo($host);
201 
202  // If a TLS session is required, commence negotiation
203  if ($this->_secure == 'tls') {
204  $this->_send('STARTTLS');
205  $this->_expect(220, 180);
206  // TODO: Add STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT in the future when it is supported by PHP
207  if (!stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT)) {
211  #require_once 'Zend/Mail/Protocol/Exception.php';
212  throw new Zend_Mail_Protocol_Exception('Unable to connect via TLS');
213  }
214  $this->_ehlo($host);
215  }
216 
217  $this->_startSession();
218  $this->auth();
219  }
_expect($code, $timeout=null)
Definition: Abstract.php:402

◆ mail()

mail (   $from)

Issues MAIL command

Parameters
string$fromSender mailbox
Exceptions
Zend_Mail_Protocol_Exception
Returns
void
See also
Zend_Mail_Protocol_Exception

Definition at line 251 of file Smtp.php.

252  {
253  if ($this->_sess !== true) {
257  #require_once 'Zend/Mail/Protocol/Exception.php';
258  throw new Zend_Mail_Protocol_Exception('A valid session has not been started');
259  }
260 
261  $this->_send('MAIL FROM:<' . $from . '>');
262  $this->_expect(250, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
263 
264  // Set mail to true, clear recipients and any existing data flags as per 4.1.1.2 of RFC 2821
265  $this->_mail = true;
266  $this->_rcpt = false;
267  $this->_data = false;
268  }
_expect($code, $timeout=null)
Definition: Abstract.php:402

◆ noop()

noop ( )

Issues the NOOP command and validates answer

Not used by Zend_Mail, could be used to keep a connection alive or check if it is still open.

Returns
void

Definition at line 356 of file Smtp.php.

357  {
358  $this->_send('NOOP');
359  $this->_expect(250, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
360  }
_expect($code, $timeout=null)
Definition: Abstract.php:402

◆ quit()

quit ( )

Issues the QUIT command and clears the current session

Returns
void

Definition at line 383 of file Smtp.php.

384  {
385  if ($this->_sess) {
386  $this->_send('QUIT');
387  $this->_expect(221, 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
388  $this->_stopSession();
389  }
390  }
_expect($code, $timeout=null)
Definition: Abstract.php:402

◆ rcpt()

rcpt (   $to)

Issues RCPT command

Parameters
string$toReceiver(s) mailbox
Exceptions
Zend_Mail_Protocol_Exception
Returns
void
See also
Zend_Mail_Protocol_Exception

Definition at line 278 of file Smtp.php.

279  {
280  if ($this->_mail !== true) {
284  #require_once 'Zend/Mail/Protocol/Exception.php';
285  throw new Zend_Mail_Protocol_Exception('No sender reverse path has been supplied');
286  }
287 
288  // Set rcpt to true, as per 4.1.1.3 of RFC 2821
289  $this->_send('RCPT TO:<' . $to . '>');
290  $this->_expect(array(250, 251), 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
291  $this->_rcpt = true;
292  }
_expect($code, $timeout=null)
Definition: Abstract.php:402

◆ rset()

rset ( )

Issues the RSET command and validates answer

Can be used to restore a clean smtp communication state when a transaction has been cancelled or commencing a new transaction.

Returns
void

Definition at line 337 of file Smtp.php.

338  {
339  $this->_send('RSET');
340  // MS ESMTP doesn't follow RFC, see [ZF-1377]
341  $this->_expect(array(250, 220));
342 
343  $this->_mail = false;
344  $this->_rcpt = false;
345  $this->_data = false;
346  }
_expect($code, $timeout=null)
Definition: Abstract.php:402

◆ vrfy()

vrfy (   $user)

Issues the VRFY command and validates answer

Not used by Zend_Mail.

Parameters
string$userUser Name or eMail to verify
Returns
void

Definition at line 371 of file Smtp.php.

372  {
373  $this->_send('VRFY ' . $user);
374  $this->_expect(array(250, 251, 252), 300); // Timeout set for 5 minutes as per RFC 2821 4.5.3.2
375  }
_expect($code, $timeout=null)
Definition: Abstract.php:402
$user
Definition: dummy_user.php:13

Field Documentation

◆ $_auth

$_auth = false
protected

Definition at line 87 of file Smtp.php.

◆ $_data

$_data = null
protected

Definition at line 111 of file Smtp.php.

◆ $_helo

$_helo = false
protected

Definition at line 79 of file Smtp.php.

◆ $_mail

$_mail = false
protected

Definition at line 95 of file Smtp.php.

◆ $_rcpt

$_rcpt = false
protected

Definition at line 103 of file Smtp.php.

◆ $_secure

$_secure
protected

Definition at line 63 of file Smtp.php.

◆ $_sess

$_sess = false
protected

Definition at line 71 of file Smtp.php.

◆ $_transport

$_transport = 'tcp'
protected

Definition at line 55 of file Smtp.php.


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