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" ] ]
Properties
default_transport
protected string $default_transport = 'local'
transport
protected Transport $transport
message
protected TransportMessage $message
subject
public Template $subject
body
protected mixed $body
last_to
protected array $last_to
config
protected array $config
Methods
__construct
The mail class constructor.
public __construct(?array $config): void
If a transport is not provided then the [[Hazaar\Mail\Transport\Local]] transport will be used.
Parameters
Parameter | Type | Description |
---|---|---|
$config | array | the configuration settings for the mail adapter |
getTransportObject
Get the transport object for the specified transport backend.
public getTransportObject(string $transport = 'local', array $config = []): Transport
Parameters
Parameter | Type | Description |
---|---|---|
$transport | string | The transport backend to use. Options are local, or smtp. |
$config | array | The configuration settings for the transport backend |
setDefaultTransport
public setDefaultTransport(string $transport): void
Parameters
Parameter | Type | Description |
---|---|---|
$transport | string |
setFrom
Set the 'From:' address header of the email.
public setFrom(string $email, ?string $name): 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): 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): 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 $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(string $email, ?string $name): void
Parameters
Parameter | Type | Description |
---|---|---|
$email | string | The email address |
$name | string | The name part |
getTo
Get the 'To:' address header of the email.
public getTo(): void
getLastTo
Get the last 'To:' address header of the email.
public getLastTo(): void
addCC
Set the 'CC:' address header of the email.
public addCC(string $email, ?string $name): void
Parameters
Parameter | Type | Description |
---|---|---|
$email | string | |
$name | string |
getCC
Get the 'CC:' address header of the email.
public getCC(): void
addBCC
Set the 'BCC:' address header of the email.
public addBCC(string $email, ?string $name): void
Parameters
Parameter | Type | Description |
---|---|---|
$email | string | |
$name | string |
getBCC
Get the 'BCC:' address header of the email.
public getBCC(): void
setSubject
Set the 'Subject' header of the email.
public setSubject(Template $subject): void
Parameters
Parameter | Type | Description |
---|---|---|
$subject | 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(File $file, ?string $name): void
Parameters
Parameter | Type | Description |
---|---|---|
$file | File | |
$name | string |
setBodyTemplate
Set an email template to use as the email body.
public setBodyTemplate(Template $template): void
Parameters
Parameter | Type | Description |
---|---|---|
$template | 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(array $headers): void
Parameters
Parameter | Type | Description |
---|---|---|
$headers | array |
send
Send the email using the current transport backend.
public send(array $params = []): mixed
Parameters
Parameter | Type | Description |
---|---|---|
$params | array |
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
protected encodeEmailAddress(string $email, ?string $name): void
Parameters
Parameter | Type | Description |
---|---|---|
$email | string | |
$name | string |
resetDSN
protected resetDSN(): void
Generated by Hazaar API Doc Generator