Zend\Mime\Message represents a MIME compliant message that can contain one or more separate Parts (Represented as Zend\Mime\Part objects). With Zend\Mime\Message, MIME compliant multipart messages can be generated from Zend\Mime\Part objects. Encoding and Boundary handling are handled transparently by the class. Zend\Mime\Message objects can also be reconstructed from given strings. Used by Zend\Mail.


There is no explicit constructor for Zend\Mime\Message.

Adding MIME Parts

Zend\Mime\Part Objects can be added to a given Zend\Mime\Message object by calling ->addPart($part)

An array with all Zend\Mime\Part objects in the Zend\Mime\Message is returned from the method getParts(). The Zend\Mime\Part objects can then be changed since they are stored in the array as references. If parts are added to the array or the sequence is changed, the array needs to be given back to the Zend\Mime\Part object by calling setParts($partsArray).

The function isMultiPart() will return TRUE if more than one part is registered with the Zend\Mime\Message object and thus the object would generate a Multipart-Mime-Message when generating the actual output.

Boundary handling

Zend\Mime\Message usually creates and uses its own Zend\Mime\Mime Object to generate a boundary. If you need to define the boundary or want to change the behaviour of the Zend\Mime\Mime object used by Zend\Mime\Message, you can instantiate the Zend\Mime\Mime class yourself and then register it to Zend\Mime\Message. Usually you will not need to do this. setMime(Zend\Mime\Mime $mime) sets a special instance of Zend\Mime\Mime to be used by this Zend\Mime\Message.

getMime() returns the instance of Zend\Mime\Mime that will be used to render the message when generateMessage() is called.

generateMessage() renders the Zend\Mime\Message content to a string.

Parsing a string to create a Zend\Mime\Message object

A given MIME compliant message in string form can be used to reconstruct a Zend\Mime\Message object from it. Zend\Mime\Message has a static factory Method to parse this String and return a Zend\Mime\Message object.

Zend\Mime\Message::createFromMessage($str, $boundary) decodes the given string and returns a Zend\Mime\Message object that can then be examined using getParts()

Available methods

A Zend\Mime\Message object has the following methods:

  • getParts: Get the all Zend\Mime\Parts in the message.
  • setParts($parts): Set the array of Zend\Mime\Parts for the message.
  • addPart(Zend\Mime\Part $part): Append a new Zend\Mime\Part to the message.
  • isMultiPart: Check if the message needs to be sent as a multipart MIME message.
  • setMime(Zend\Mime\Mime $mime): Set a custom Zend\Mime\Mime object for the message.
  • getMime: Get the Zend\Mime\Mime object for the message.
  • generateMessage($EOL=Zend\Mime\Mime::LINEEND): Generate a MIME-compliant message from the current configuration.
  • getPartHeadersArray($partnum): Get the headers of a given part as an array.
  • getPartHeaders($partnum,$EOL=Zend\Mime\Mime::LINEEND): Get the headers of a given part as a string.
  • getPartContent($partnum,$EOL=Zend\Mime\Mime::LINEEND): Get the encoded content of a given part as a string.

Table Of Contents

Previous topic


Next topic


This Page

Note: You need to stay logged into your GitHub account to contribute to the documentation.

Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Login with your GitHub account.
  2. Go to Zend\Mime\Message on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.