Part
Part
MIME part representing a section of an email message.
class Part implements \JsonSerializableImplements: JsonSerializable
Handles 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 $headersType: array
content
The content of the MIME part.
protected string $contentType: string
crlf
Carriage return and line feed sequence used for MIME formatting.
protected string $crlf = '"\r\n"'Type: string
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): boolReturns: bool
Iterates 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): voidReturns: void
Adds 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: string
Returns 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): voidReturns: void
Parameters
| 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(): stringReturns: string
setDescription
Sets the content description header for the MIME part.
public setDescription(string $text): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$text | string | the description text to set |
setContent
Sets the content of the MIME part.
public setContent(string $content): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string | the content to set for the part |
getContent
Retrieves the content of the MIME part.
public getContent(): stringReturns: string
detectBreak
Detects the line break sequence used in the content.
public detectBreak(string $content, string $default = '"\r\n"'): stringReturns: string
Returns "\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): stringReturns: string
Adds 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): PartReturns: Hazaar\Mail\Mime\Part
Parses 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: mixed
Returns an array containing the headers and content for use in JSON representations.
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:17 +0000