Part
Part
MIME part representing a section of an email message.
class Part implements \JsonSerializableHandles headers, content, encoding, decoding, and serialization for individual MIME parts. Supports setting and retrieving headers, content type, description, and content, as well as encoding for email transmission.
Properties
headers
protected array $headerscontent
The content of the MIME part.
protected string $contentcrlf
Carriage return and line feed sequence used for MIME formatting.
protected string $crlf = '"\r\n"'Methods
__construct
Constructs a new MIME part instance.
public __construct(?string $content, ?string $contentType, array $headers): voidInitializes the part with optional content, content type, and headers. Sets the content and content type if provided, and applies any headers.
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string | the content of the MIME part (optional) |
$contentType | string | The MIME content type (e.g., 'text/plain', 'text/html') (optional). |
$headers | array | associative array of headers to set for the part (optional) |
setHeaders
Sets multiple headers for the MIME part.
public setHeaders(array $headers): boolIterates over the provided associative array and sets each header using setHeader(). Returns true when complete.
Parameters
| Parameter | Type | Description |
|---|---|---|
$headers | array | associative array of header names and values to set |
setHeader
Sets a header for the MIME part.
public setHeader(string $header, string $content): voidAdds or updates the specified header with the provided content value.
Parameters
| Parameter | Type | Description |
|---|---|---|
$header | string | The name of the header to set (e.g., 'Content-Type'). |
$content | string | the value of the header |
getHeader
Retrieves the value of a specific header from the MIME part.
public getHeader(string $header): stringReturns the header value if set, or an empty string if not found.
Parameters
| Parameter | Type | Description |
|---|---|---|
$header | string | the name of the header to retrieve |
setContentType
Sets the content type header for the MIME part.
public setContentType(string $type): voidParameters
| Parameter | Type | Description |
|---|---|---|
$type | string | The MIME content type (e.g., 'text/plain', 'text/html'). |
getContentType
Retrieves the content type of the MIME part.
public getContentType(): stringsetDescription
Sets the content description header for the MIME part.
public setDescription(string $text): voidParameters
| Parameter | Type | Description |
|---|---|---|
$text | string | the description text to set |
setContent
Sets the content of the MIME part.
public setContent(string $content): voidParameters
| Parameter | Type | Description |
|---|---|---|
$content | string | the content to set for the part |
getContent
Retrieves the content of the MIME part.
public getContent(): stringdetectBreak
Detects the line break sequence used in the content.
public detectBreak(string $content, string $default = '"\r\n"'): stringReturns "\r\n" if CRLF is detected, "\n" otherwise, or the provided default if no line break is found.
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string | the content to analyze for line breaks |
$default | string | the default line break sequence to return if none is detected (default: "\r\n") |
encode
Encodes the MIME part into a string suitable for email transmission.
public encode(int $widthLimit = 76): stringAdds headers, applies line wrapping to the content, and includes a date header. Handles content type encoding and charset detection.
Parameters
| Parameter | Type | Description |
|---|---|---|
$widthLimit | int | the maximum line width for encoding (default: 76) |
decode
Decodes a raw MIME part string into a Part object.
public decode(string $data): PartParses headers and content from the input string and constructs a new Part instance.
Parameters
| Parameter | Type | Description |
|---|---|---|
$data | string | the raw MIME part string to decode |
jsonSerialize
Serializes the MIME part for JSON encoding.
public jsonSerialize(): mixedReturns an array containing the headers and content for use in JSON representations.
Generated by Hazaar API Doc Generator on Tue, 21 Apr 2026 04:00:23 +0000