Download the PHP package popphp/pop-mime without Composer
On this page you can find all versions of the php package popphp/pop-mime. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download popphp/pop-mime
More information about popphp/pop-mime
Files in popphp/pop-mime
Package pop-mime
Short Description Pop Mime Component for Pop PHP Framework
License BSD-3-Clause
Homepage http://www.popphp.org/
Informations about the package pop-mime
pop-mime
- Overview
- Install
- Quickstart
- Parts
- Attachments
- Headers
- Header Values
- Multiple Header Values
- Multipart Messages
- Parsing
Overview
pop-mime
is a component that provides the ability to work with MIME messages and content. With it, you can
generate properly-formatted MIME messages with all their related headers and parts, or you can parse pre-existing
MIME messages into their respective objects and work with them from there. This can be utilized with mail and HTTP
components, such as pop-mail
and pop-http
.
pop-mime
is a component of the Pop PHP Framework.
Install
Install pop-mime
using Composer.
composer require popphp/pop-mime
Or, require it in your composer.json file
"require": {
"popphp/pop-mime" : "^2.0.0"
}
Top
Quickstart
Creating a Simple MIME Message:
This will produce the following MIME message:
Top
Parts
The main message object is essentially a top-level part object. A part object can contain headers, a body object or other nested part objects. When a part object has nested parts, this creates a multipart message. The required boundaries are automatically generated.
The example above would produce:
Top
Attachments
Part objects can be file attachments as well.
The example above would produce:
Top
Headers
The header and header value objects allow for easy creation and granular control over the header values of a MIME message.
Top
Header Values
Header values can be passed into a header object as strings, but they will become header value objects. When fetching them, you can get the value object like this:
The benefit of the header value object is that it allows fine-grain control over the header value, including scheme, parameters, the delimiter and whether or not to force quotes.
Example 1:
Example 2:
You can always get the header value as a string:
Top
Multiple Header Values
In some cases, a header may need to contain multiple values. They can be passed as an array to the constructor:
or, by individual header value object:
You can access each header value by index:
Top
Multipart Messages
There is a interface to assist in easily creating multipart messages, instead of doing it the more manual way outlined in the above examples.
HTTP Multipart Form
If you just need the main form parts without the top-level header and MIME preamble, you can do that like this:
And that will render just the form data content, removing the top-level header and the preamble:
HTTP Multipart Form with a File
You can also create form data with files in a couple of different ways as well:
Example 1:
Example 2:
In example 1, the file on disk is passed and put into the form data from there.
In example 2, the file contents are explicitly passed to the contents
key to
set the file data into the form data. Also, for flexibility, the following
case-insensitive keys are acceptable for Content-Type
:
- Content-Type
- contentType
- Mime-Type
- mimeType
- mime
Top
Parsing
Note:
This component adheres to the MIME standard which uses CRLF ("\r\n") for line breaks. If a mime message does not adhere to this standard, parsing may not work as intended.
Parsing a message:
To parse MIME messages and content, you can take the string of MIME message content and pass it in the following method and it will return a message object with all of the related headers and parts.
Parsing a header string:
If you happen to have the MIME header string, you can parse just that like below. This will return an array of header objects:
Parsing a body string:
If you happen to have the MIME body string, you can parse just that like below. This will return an array of part objects:
Parsing a single part string:
And if you happen to have the string of a single MIME part, you can parse just that like below. This will return a part object:
Parsing form data:
As a special case, if you have multipart/form-data
MIME content, you can parse
it like below. This will return a form data array:
It's important to note that in order for the above example to work properly, it
has to have a header with at least the Content-Type
defined, including the boundary
that will be used in parsing the form data:
Top