Adapter
Adapter
Common class for sending emails via different transport mechanisms.
This 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 = FALSE
except 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" ] ]
- Full name:
\Hazaar\Mail\Adapter
Properties
default_transport
protected static string $default_transport
- This property is static.
transport
protected \Hazaar\Mail\Transport $transport
message
protected \Hazaar\Mail\TransportMessage $message
subject
protected string|\Hazaar\Mail\Template $subject
body
protected mixed $body
last_to
protected array $last_to
config
protected \Hazaar\Map $config
Methods
__construct
The mail class constructor.
public __construct(array|\Hazaar\Map $config = null): mixed
If a transport is not provided then the [[Hazaar\Mail\Transport\Local]] transport will be used.
Parameters:
Parameter | Type | Description |
---|---|---|
$config | array|\Hazaar\Map | the configuration settings for the mail adapter |
getTransportObject
public getTransportObject(string $transport = 'local', ?\Hazaar\Map $config = null): \Hazaar\Mail\Transport
Parameters:
Parameter | Type | Description |
---|---|---|
$transport | string | |
$config | ?\Hazaar\Map |
setDefaultTransport
Set the transport backend that should be used.
public static setDefaultTransport(string $transport): void
- This method is static.
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 = null): 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 = null): 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, null|string $name = null): void
Parameters:
Parameter | Type | Description |
---|---|---|
$email | string | the email address to set as the return path |
$name | null|string | the name associated with the email address (optional) |
clear
Clear all recipients ready for re-using the adapter.
public clear(bool $clear_attachments = false): void
This is for working with templates that need to be sent/rendered multiple times to send to many recipients.
Parameters:
Parameter | Type | Description |
---|---|---|
$clear_attachments | bool |
addTo
Set the 'To:' address header of the email.
public addTo(array|string $email, string $name = null): void
Parameters:
Parameter | Type | Description |
---|---|---|
$email | array|string | The email address |
$name | string | The name part |
getTo
Get the 'To:' address header of the email.
public getTo(): array
getLastTo
Get the last 'To:' address header of the email.
public getLastTo(): array
addCC
Set the 'CC:' address header of the email.
public addCC(string[]|string $email, ?string $name = null): void
Parameters:
Parameter | Type | Description |
---|---|---|
$email | string[]|string | |
$name | ?string |
getCC
Get the 'CC:' address header of the email.
public getCC(): array
addBCC
Set the 'BCC:' address header of the email.
public addBCC(string[]|string $email, ?string $name = null): void
Parameters:
Parameter | Type | Description |
---|---|---|
$email | string[]|string | |
$name | ?string |
getBCC
Get the 'BCC:' address header of the email.
public getBCC(): array
setSubject
Set the 'Subject' header of the email.
public setSubject(string|\Hazaar\Mail\Template $subject): void
Parameters:
Parameter | Type | Description |
---|---|---|
$subject | string|\Hazaar\Mail\Template |
setBodyText
Sets the plain text body of the email.
public setBodyText(string $body): 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(mixed $html): void
Parameters:
Parameter | Type | Description |
---|---|---|
$html | mixed |
addAttachment
public addAttachment(\Hazaar\Mail\Attachment|\Hazaar\File $file, ?string $name = null): 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(\Hazaar\Mail\Template $template): 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): 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): 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 = []): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$params | array |
setExtraHeaders
Set extra headers to be included in the email.
public setExtraHeaders(string[] $headers): void
Parameters:
Parameter | Type | Description |
---|---|---|
$headers | string[] |
send
Send the email using the current transport backend.
public send(array $params = []): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$params | array |
Return Value:
false if the email was not sent, or the result of the transport send method
enableDSN
Enables ALL Delivery Status Notification types.
public enableDSN(): void
disableDSN
Disable ALL Delivery Status Notifications.
public disableDSN(): void
enableDSNSuccess
Enables SUCCESS Delivery Status Notification types.
public enableDSNSuccess(): void
enableDSNFailure
Enables SUCCESS Delivery Status Notification types.
public enableDSNFailure(): void
enableDSNDelay
Enables SUCCESS Delivery Status Notification types.
public enableDSNDelay(): void
encodeEmailAddress
Encodes an email address into RFC5322 standard format.
protected static encodeEmailAddress(string[]|string $email, string $name = null): string[]
- This method is static.
Parameters:
Parameter | Type | Description |
---|---|---|
$email | string[]|string | The email address |
$name | string | The name part |
Return Value:
An array containing the email address and name
resetDSN
protected resetDSN(): void
Automatically generated on 2024-11-14