Adapter
Adapter
Common class for sending emails via different transport mechanisms.
class AdapterThis class provides a common interface for send emails via transport backends. These backends can be anything from local sendmail execution via the PHP mail() command, or directly using SMTP.
Configuration Settings
- enable - BOOLEAN - This is TRUE by default. Setting to FALSE will cause any calls to
Adapter::send()to throw an\Exception. - transport - STRING - This is the default transport to use when one is not specified. Currently supports 'local' and 'smtp'.
- testmode - BOOLEAN - This is FALSE by default. Setting it to TRUE will activate test mode. This is exactly the same as disabling emails with
enable = FALSEexcept that it will simulate a successful transmission. - override - This allows recipient emails to be overriden with the email address listed.
- to - ARRAY - Override all 'to' recipient addresses with the list provided.
- cc - ARRAY - Override all 'cc' recipient addresses with the list provided.
- bcc - ARRAY - Override all 'bcc' recipient addresses with the list provided.
- noOverrideMatch - REGEX - Do not override any 'to' recipient email address that match this regex.
Override email address can be either plain strings, or an Array where index 0 is the email address, and index 1 is the recipient name.
Example #1: [ "[email protected]" ]
Example #2: [ [ "[email protected]", "Hazaar Labs Support" ] ]
Properties
defaultTransport
The default transport backend to use for sending emails.
protected string $defaultTransport = 'local'Type: string
transport
The transport object used to send emails.
protected Transport $transportType: Hazaar\Mail\Transport
message
The message object representing the email being constructed and sent.
protected TransportMessage $messageType: Hazaar\Mail\TransportMessage
subject
The subject of the email, which can be a string or a Template object for dynamic rendering.
protected string|Template $subjectType: string|Hazaar\Mail\Template
body
The body of the email, which can be plain text, HTML, or a Template object.
protected Mime\Message|Mime\Part|Template $bodyType: Hazaar\Mail\Mime\Message|Hazaar\Mail\Mime\Part|Hazaar\Mail\Template
lastTo
protected array $lastToType: array
config
protected Adapter\Options $configType: Hazaar\Mail\Adapter\Options
Methods
__construct
The mail class constructor.
public __construct(Adapter\Options|array|null $config): voidIf a transport is not provided then the Hazaar\Mail\Transport\Local transport will be used.
Parameters
| Parameter | Type | Description |
|---|---|---|
$config | Hazaar\Mail\Adapter\Options | array |
getTransportObject
Get the transport object for the specified transport backend.
public getTransportObject(string $transport = 'local', array $config): TransportReturns: Hazaar\Mail\Transport
Instantiates and returns the appropriate transport class (Local, SMTP, HTTP, etc.) based on the provided name and configuration. Throws an exception if the transport class does not exist.
Parameters
| Parameter | Type | Description |
|---|---|---|
$transport | string | The transport backend to use. Options are 'local', 'smtp', or 'http'. |
$config | array | the configuration settings for the transport backend |
setDefaultTransport
Set the transport backend that should be used.
public setDefaultTransport(string $transport): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$transport | string | The transport backend to use. Options are local, or smtp. |
setFrom
Set the 'From:' address header of the email.
public setFrom(string $email, ?string $name): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$email | string | The email address |
$name | string | The name part |
setReplyTo
Set the 'Reply-To:' address header of the email.
public setReplyTo(string $email, ?string $name): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$email | string | The email address |
$name | string | The name part |
setReturnPath
Sets the return path for the email.
public setReturnPath(string $email, ?string $name): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$email | string | the email address to set as the return path |
$name | string | the name associated with the email address (optional) |
clear
Clear all recipients ready for re-using the adapter.
public clear(bool $clearAttachments): voidReturns: void
This is for working with templates that need to be sent/rendered multiple times to send to many recipients.
Parameters
| Parameter | Type | Description |
|---|---|---|
$clearAttachments | bool |
addTo
Set the 'To:' address header of the email.
public addTo(array|string $email, ?string $name): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$email | array | string |
$name | string | The name part |
getTo
Get the 'To:' address header of the email.
public getTo(): arrayReturns: array
getLastTo
Get the last 'To:' address header of the email.
public getLastTo(): arrayReturns: array
addCC
Set the 'CC:' address header of the email.
public addCC(array|string $email, ?string $name): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$email | array | string |
$name | string |
getCC
Get the 'CC:' address header of the email.
public getCC(): arrayReturns: array
addBCC
Set the 'BCC:' address header of the email.
public addBCC(array|string $email, ?string $name): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$email | array | string |
$name | string |
getBCC
Get the 'BCC:' address header of the email.
public getBCC(): arrayReturns: array
setSubject
Set the 'Subject' header of the email.
public setSubject(string|Template $subject): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$subject | string | Hazaar\Mail\Template |
setBodyText
Sets the plain text body of the email.
public setBodyText(string $body): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$body | string | The plain text body of the email |
setBodyHTML
Sets a the HTML body of the email.
public setBodyHTML(Mime\Message|Mime\Part|string|Template $html): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$html | Hazaar\Mail\Mime\Message | Hazaar\Mail\Mime\Part |
addAttachment
public addAttachment(Attachment|File $file, ?string $name): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$file | Hazaar\Mail\Attachment | Hazaar\File |
$name | string |
setBodyTemplate
Set an email template to use as the email body.
public setBodyTemplate(Template $template): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$template | Hazaar\Mail\Template | the template to use |
loadTemplate
Load load a template to use as the TEXT email body.
public loadTemplate(string $filename): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$filename | string | The filename to load the template from |
loadHTMLTemplate
Load a template to use as the HTML email body.
public loadHTMLTemplate(string $filename): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$filename | string | The filename to load the template from |
getBody
Get the current body part of the email.
public getBody(array $params): Mime\Message|stringReturns: Hazaar\Mail\Mime\Message|string
Parameters
| Parameter | Type | Description |
|---|---|---|
$params | array |
setExtraHeaders
Set extra headers to be included in the email.
public setExtraHeaders(array $headers): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$headers | array |
send
Send the email using the current transport backend.
public send(array $params): mixedReturns: mixed
Parameters
| Parameter | Type | Description |
|---|---|---|
$params | array |
enableDSN
Enables ALL Delivery Status Notification types.
public enableDSN(): voidReturns: void
disableDSN
Disable ALL Delivery Status Notifications.
public disableDSN(): voidReturns: void
enableDSNSuccess
Enables SUCCESS Delivery Status Notification types.
public enableDSNSuccess(): voidReturns: void
enableDSNFailure
Enables SUCCESS Delivery Status Notification types.
public enableDSNFailure(): voidReturns: void
enableDSNDelay
Enables SUCCESS Delivery Status Notification types.
public enableDSNDelay(): voidReturns: void
encodeEmailAddress
Encodes an email address into RFC5322 standard format.
protected encodeEmailAddress(array|string $email, ?string $name): arrayReturns: array
Parameters
| Parameter | Type | Description |
|---|---|---|
$email | array | string |
$name | string | The name part |
resetDSN
protected resetDSN(): voidReturns: void
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:17 +0000