Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Zend_Mail_Transport_Sendmail Class Reference
Inheritance diagram for Zend_Mail_Transport_Sendmail:
Zend_Mail_Transport_Abstract

Public Member Functions

 __construct ($parameters=null)
 
 _sendMail ()
 
 _handleMailErrors ($errno, $errstr, $errfile=null, $errline=null, array $errcontext=null)
 
- Public Member Functions inherited from Zend_Mail_Transport_Abstract
 send (Zend_Mail $mail)
 

Data Fields

 $subject = null
 
 $parameters
 
 $EOL = PHP_EOL
 
- Data Fields inherited from Zend_Mail_Transport_Abstract
 $body = ''
 
 $boundary = ''
 
 $header = ''
 
 $recipients = ''
 
 $EOL = "\r\n"
 

Protected Member Functions

 _prepareHeaders ($headers)
 
- Protected Member Functions inherited from Zend_Mail_Transport_Abstract
 _sendMail ()
 
 _getHeaders ($boundary)
 
 _prepareHeaders ($headers)
 
 _buildBody ()
 

Protected Attributes

 $_errstr
 
- Protected Attributes inherited from Zend_Mail_Transport_Abstract
 $_headers = array()
 
 $_isMultipart = false
 
 $_mail = false
 
 $_parts = array()
 

Additional Inherited Members

- Static Protected Member Functions inherited from Zend_Mail_Transport_Abstract
static _formatHeader (&$item, $key, $prefix)
 

Detailed Description

Definition at line 39 of file Sendmail.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $parameters = null)

Constructor.

Parameters
string | array | Zend_Config$parametersOPTIONAL (Default: null)
Returns
void

Definition at line 74 of file Sendmail.php.

75  {
76  if ($parameters instanceof Zend_Config) {
77  $parameters = $parameters->toArray();
78  }
79 
80  if (is_array($parameters)) {
81  $parameters = implode(' ', $parameters);
82  }
83 
84  $this->parameters = $parameters;
85  }

Member Function Documentation

◆ _handleMailErrors()

_handleMailErrors (   $errno,
  $errstr,
  $errfile = null,
  $errline = null,
array  $errcontext = null 
)

Temporary error handler for PHP native mail().

Parameters
int$errno
string$errstr
string$errfile
string$errline
array$errcontext
Returns
true

Definition at line 199 of file Sendmail.php.

200  {
201  $this->_errstr = $errstr;
202  return true;
203  }

◆ _prepareHeaders()

_prepareHeaders (   $headers)
protected

Format and fix headers

mail() uses its $to and $subject arguments to set the To: and Subject: headers, respectively. This method strips those out as a sanity check to prevent duplicate header entries.

@access protected

Parameters
array$headers
Returns
void
Exceptions
Zend_Mail_Transport_Exception
See also
Zend_Mail_Transport_Exception
Zend_Mail_Transport_Exception
Zend_Mail_Transport_Exception

Definition at line 127 of file Sendmail.php.

128  {
129  if (!$this->_mail) {
133  #require_once 'Zend/Mail/Transport/Exception.php';
134  throw new Zend_Mail_Transport_Exception('_prepareHeaders requires a registered Zend_Mail object');
135  }
136 
137  // mail() uses its $to parameter to set the To: header, and the $subject
138  // parameter to set the Subject: header. We need to strip them out.
139  if (0 === strpos(PHP_OS, 'WIN')) {
140  // If the current recipients list is empty, throw an error
141  if (empty($this->recipients)) {
145  #require_once 'Zend/Mail/Transport/Exception.php';
146  throw new Zend_Mail_Transport_Exception('Missing To addresses');
147  }
148  } else {
149  // All others, simply grab the recipients and unset the To: header
150  if (!isset($headers['To'])) {
154  #require_once 'Zend/Mail/Transport/Exception.php';
155  throw new Zend_Mail_Transport_Exception('Missing To header');
156  }
157 
158  unset($headers['To']['append']);
159  $this->recipients = implode(',', $headers['To']);
160  }
161 
162  // Remove recipient header
163  unset($headers['To']);
164 
165  // Remove subject header, if present
166  if (isset($headers['Subject'])) {
167  unset($headers['Subject']);
168  }
169 
170  // Sanitize the From header
171  if (isset($headers['From'])) {
172  $addressList = array_filter($headers['From'], function ($key) {
173  return $key !== 'append';
174  }, ARRAY_FILTER_USE_KEY);
175  foreach ($addressList as $address) {
176  if (preg_match('/\\\"/', $address)) {
177  throw new Zend_Mail_Transport_Exception('Potential code injection in From header');
178  }
179  }
180  }
181 
182  // Prepare headers
183  parent::_prepareHeaders($headers);
184 
185  // Fix issue with empty blank line ontop when using Sendmail Trnasport
186  $this->header = rtrim($this->header);
187  }
$address
Definition: customer.php:38

◆ _sendMail()

_sendMail ( )

Send mail using PHP native mail()

@access public

Returns
void
Exceptions
Zend_Mail_Transport_Exceptionif parameters is set but not a string
Zend_Mail_Transport_Exceptionon mail() failure
See also
Zend_Mail_Transport_Exception

Definition at line 96 of file Sendmail.php.

97  {
98  set_error_handler(array($this, '_handleMailErrors'));
99  $result = mail(
100  $this->recipients,
101  $this->_mail->getSubject(),
102  $this->body,
103  $this->header);
104  restore_error_handler();
105 
106  if ($this->_errstr !== null || !$result) {
110  #require_once 'Zend/Mail/Transport/Exception.php';
111  throw new Zend_Mail_Transport_Exception('Unable to send mail. ' . $this->_errstr);
112  }
113  }

Field Documentation

◆ $_errstr

$_errstr
protected

Definition at line 66 of file Sendmail.php.

◆ $EOL

$EOL = PHP_EOL

Definition at line 60 of file Sendmail.php.

◆ $parameters

$parameters

Definition at line 53 of file Sendmail.php.

◆ $subject

$subject = null

Definition at line 46 of file Sendmail.php.


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