Html
Html
MIME part representing an HTML email body.
class Html extends \Hazaar\Mail\Mime\Part implements \JsonSerializableExtends: Hazaar\Mail\Mime\Part
Implements: JsonSerializable
Handles multipart/alternative encoding, template rendering, and conversion to string or JSON. Supports setting template parameters and encoding both HTML and plain text versions for email clients.
Properties
boundary
Boundary string for multipart/alternative encoding.
private string $boundaryType: string
html
The HTML template instance for rendering the email body.
private Template $htmlType: Hazaar\Mail\Template
params
Parameters to be passed to the HTML template for rendering.
private array $paramsType: array
Methods
__construct
Constructs a new Html MIME part for email messages.
public __construct(string|Template $html, array $headers): voidAccepts either a string or a Template instance for the HTML content. Sets up the multipart/alternative boundary and content type.
Parameters
| Parameter | Type | Description |
|---|---|---|
$html | string | Hazaar\Mail\Template |
$headers | array | optional headers to include in the MIME part |
__toString
Converts the HTML MIME part to a string by encoding it.
public __toString(): stringReturns: string
setParams
Sets the parameters for the HTML template rendering.
public setParams(array $params): voidReturns: void
These parameters are used when rendering the HTML content for the email body.
Parameters
| Parameter | Type | Description |
|---|---|---|
$params | array | associative array of template parameters to set |
encode
Encodes the HTML MIME part as a multipart/alternative message.
public encode(int $widthLimit = 998): stringReturns: string
Renders the HTML template with the set parameters, creates both HTML and plain text parts, and combines them using the boundary for email clients.
Parameters
| Parameter | Type | Description |
|---|---|---|
$widthLimit | int | the maximum line width for encoding (default: 998) |
jsonSerialize
Serializes the HTML MIME part for JSON encoding.
public jsonSerialize(): mixedReturns: mixed
Returns an array containing the type, headers, and rendered HTML content for use in JSON representations.
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:17 +0000