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

Public Member Functions

 send (Zend_Mail $mail)
 

Data Fields

 $body = ''
 
 $boundary = ''
 
 $header = ''
 
 $recipients = ''
 
 $EOL = "\r\n"
 

Protected Member Functions

 _sendMail ()
 
 _getHeaders ($boundary)
 
 _prepareHeaders ($headers)
 
 _buildBody ()
 

Static Protected Member Functions

static _formatHeader (&$item, $key, $prefix)
 

Protected Attributes

 $_headers = array()
 
 $_isMultipart = false
 
 $_mail = false
 
 $_parts = array()
 

Detailed Description

Definition at line 40 of file Abstract.php.

Member Function Documentation

◆ _buildBody()

_buildBody ( )
protected

Generate MIME compliant message from the current configuration

If both a text and HTML body are present, generates a multipart/alternative Zend_Mime_Part containing the headers and contents of each. Otherwise, uses whichever of the text or HTML parts present.

The content part is then prepended to the list of Zend_Mime_Parts for this message.

Returns
void
See also
Zend_Mail_Transport_Exception

Definition at line 233 of file Abstract.php.

234  {
235  if (($text = $this->_mail->getBodyText())
236  && ($html = $this->_mail->getBodyHtml()))
237  {
238  // Generate unique boundary for multipart/alternative
239  $mime = new Zend_Mime(null);
240  $boundaryLine = $mime->boundaryLine($this->EOL);
241  $boundaryEnd = $mime->mimeEnd($this->EOL);
242 
243  $text->disposition = false;
244  $html->disposition = false;
245 
246  $body = $boundaryLine
247  . $text->getHeaders($this->EOL)
248  . $this->EOL
249  . $text->getContent($this->EOL)
250  . $this->EOL
251  . $boundaryLine
252  . $html->getHeaders($this->EOL)
253  . $this->EOL
254  . $html->getContent($this->EOL)
255  . $this->EOL
256  . $boundaryEnd;
257 
258  $mp = new Zend_Mime_Part($body);
260  $mp->boundary = $mime->boundary();
261 
262  $this->_isMultipart = true;
263 
264  // Ensure first part contains text alternatives
265  array_unshift($this->_parts, $mp);
266 
267  // Get headers
268  $this->_headers = $this->_mail->getHeaders();
269  return;
270  }
271 
272  // If not multipart, then get the body
273  if (false !== ($body = $this->_mail->getBodyHtml())) {
274  array_unshift($this->_parts, $body);
275  } elseif (false !== ($body = $this->_mail->getBodyText())) {
276  array_unshift($this->_parts, $body);
277  }
278 
279  if (!$body) {
283  #require_once 'Zend/Mail/Transport/Exception.php';
284  throw new Zend_Mail_Transport_Exception('No body specified');
285  }
286 
287  // Get headers
288  $this->_headers = $this->_mail->getHeaders();
289  $headers = $body->getHeadersArray($this->EOL);
290  foreach ($headers as $header) {
291  // Headers in Zend_Mime_Part are kept as arrays with two elements, a
292  // key and a value
293  $this->_headers[$header[0]] = array($header[1]);
294  }
295  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
endifif( $block->getLastPageNum()>1)( 'Page') ?></strong >< ul class $text
Definition: pager.phtml:43
const MULTIPART_ALTERNATIVE
Definition: Mime.php:43

◆ _formatHeader()

static _formatHeader ( $item,
  $key,
  $prefix 
)
staticprotected

Prepend header name to header value

Parameters
string$item
string$key
string$prefix@access protected
Returns
void

Definition at line 165 of file Abstract.php.

166  {
167  $item = $prefix . ': ' . $item;
168  }
$prefix
Definition: name.phtml:25

◆ _getHeaders()

_getHeaders (   $boundary)
protected

Return all mail headers as an array

If a boundary is given, a multipart header is generated with a Content-Type of either multipart/alternative or multipart/mixed depending on the mail parts present in the Zend_Mail object present.

Parameters
string$boundary
Returns
array

Definition at line 127 of file Abstract.php.

128  {
129  if (null !== $boundary) {
130  // Build multipart mail
131  $type = $this->_mail->getType();
132  if (!$type) {
133  if ($this->_mail->hasAttachments) {
135  } elseif ($this->_mail->getBodyText() && $this->_mail->getBodyHtml()) {
137  } else {
139  }
140  }
141 
142  $this->_headers['Content-Type'] = array(
143  $type . ';'
144  . $this->EOL
145  . " " . 'boundary="' . $boundary . '"'
146  );
147  $this->boundary = $boundary;
148  }
149 
150  $this->_headers['MIME-Version'] = array('1.0');
151 
152  return $this->_headers;
153  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$type
Definition: item.phtml:13
const MULTIPART_ALTERNATIVE
Definition: Mime.php:43
const MULTIPART_MIXED
Definition: Mime.php:44

◆ _prepareHeaders()

_prepareHeaders (   $headers)
protected

Prepare header string for use in transport

Prepares and generates $header based on the headers provided.

Parameters
mixed$headers@access protected
Returns
void
Exceptions
Zend_Mail_Transport_Exceptionif any header lines exceed 998 characters
See also
Zend_Mail_Transport_Exception
Zend_Mail_Transport_Exception

Definition at line 181 of file Abstract.php.

182  {
183  if (!$this->_mail) {
187  #require_once 'Zend/Mail/Transport/Exception.php';
188  throw new Zend_Mail_Transport_Exception('Missing Zend_Mail object in _mail property');
189  }
190 
191  $this->header = '';
192 
193  foreach ($headers as $header => $content) {
194  if (isset($content['append'])) {
195  unset($content['append']);
196  $value = implode(',' . $this->EOL . ' ', $content);
197  $this->header .= $header . ': ' . $value . $this->EOL;
198  } else {
199  array_walk($content, array(get_class($this), '_formatHeader'), $header);
200  $this->header .= implode($this->EOL, $content) . $this->EOL;
201  }
202  }
203 
204  // Sanity check on headers -- should not be > 998 characters
205  $sane = true;
206  foreach (explode($this->EOL, $this->header) as $line) {
207  if (strlen(trim($line)) > 998) {
208  $sane = false;
209  break;
210  }
211  }
212  if (!$sane) {
216  #require_once 'Zend/Mail/Transport/Exception.php';
217  throw new Zend_Mail_Exception('At least one mail header line is too long');
218  }
219  }
$value
Definition: gender.phtml:16

◆ _sendMail()

_sendMail ( )
abstractprotected

Send an email independent from the used transport

The requisite information for the email will be found in the following properties:

◆ send()

send ( Zend_Mail  $mail)

Send a mail using this transport

Parameters
Zend_Mail$mail@access public
Returns
void
Exceptions
Zend_Mail_Transport_Exceptionif mail is empty
See also
Zend_Mail_Transport_Exception

Definition at line 305 of file Abstract.php.

306  {
307  $this->_isMultipart = false;
308  $this->_mail = $mail;
309  $this->_parts = $mail->getParts();
310  $mime = $mail->getMime();
311 
312  // Build body content
313  $this->_buildBody();
314 
315  // Determine number of parts and boundary
316  $count = count($this->_parts);
317  $boundary = null;
318  if ($count < 1) {
322  #require_once 'Zend/Mail/Transport/Exception.php';
323  throw new Zend_Mail_Transport_Exception('Empty mail cannot be sent');
324  }
325 
326  if ($count > 1) {
327  // Multipart message; create new MIME object and boundary
328  $mime = new Zend_Mime($this->_mail->getMimeBoundary());
329  $boundary = $mime->boundary();
330  } elseif ($this->_isMultipart) {
331  // multipart/alternative -- grab boundary
332  $boundary = $this->_parts[0]->boundary;
333  }
334 
335  // Determine recipients, and prepare headers
336  $this->recipients = implode(',', $mail->getRecipients());
337  $this->_prepareHeaders($this->_getHeaders($boundary));
338 
339  // Create message body
340  // This is done so that the same Zend_Mail object can be used in
341  // multiple transports
342  $message = new Zend_Mime_Message();
343  $message->setParts($this->_parts);
344  $message->setMime($mime);
345  $this->body = $message->generateMessage($this->EOL);
346 
347  // Send to transport!
348  $this->_sendMail();
349  }
getRecipients()
Definition: Mail.php:633
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$count
Definition: recent.phtml:13
$message

Field Documentation

◆ $_headers

$_headers = array()
protected

Definition at line 68 of file Abstract.php.

◆ $_isMultipart

$_isMultipart = false
protected

Definition at line 75 of file Abstract.php.

◆ $_mail

$_mail = false
protected

Definition at line 82 of file Abstract.php.

◆ $_parts

$_parts = array()
protected

Definition at line 89 of file Abstract.php.

◆ $body

$body = ''

Definition at line 47 of file Abstract.php.

◆ $boundary

$boundary = ''

Definition at line 54 of file Abstract.php.

◆ $EOL

$EOL = "\r\n"

Definition at line 103 of file Abstract.php.

◆ $header

$header = ''

Definition at line 61 of file Abstract.php.

◆ $recipients

$recipients = ''

Definition at line 96 of file Abstract.php.


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