class Service (View source)

Properties

protected Application $app

The application instance.

protected TransportInterface $transport

The transport to be used to delivery the messages.

protected array $headers

Additional email message headers.

protected $to

List of "To" recipients (every item is an array with at key 0 the email address and at key 1 an optional name).

protected $replyto

List of "Reply-To" recipients (every item is an array with at key 0 the email address and at key 1 an optional name).

protected $cc

List of "CC" recipients (every item is an array with at key 0 the email address and at key 1 an optional name).

protected $bcc

List of "CC" recipients (every item is an array with at key 0 the email address and at key 1 an optional name).

protected string[] $from

The sender email address and its name.

protected array $data

A dictionary with the parameters to be sent to the template.

protected string $subject

The message subject.

protected Part[] $attachments

The message attachments.

protected string $template

The last leaded message template file.

protected string|false $body

The plain text body.

protected string|false $bodyHTML

The HTML body.

protected bool $testing

Are we testing this service?

protected false $throwOnFailure

Should we throw an exception if the delivery fails?

Methods

__construct(Application $app, TransportInterface $transport)

Initialize the instance.

reset()

Clean up the instance of this object (reset the class scope variables).

addParameter(string $key, mixed $val)

Adds a parameter for the mail template.

addAttachment(File $file)

Add a File entity as an attachment of the message.

addAttachmentWithHeaders(File $file, array $headers)

Add a File entity as an attachment of the message, specifying the headers of the mail MIME part.

addRawAttachment(string $content, string $filename, string $mimetype = 'application/octet-stream')

Add a mail attachment by specifying its raw binary data.

addRawAttachmentWithHeaders(string $content, string $filename, array $headers = [])

Add a mail attachment by specifying its raw binary data, specifying the headers of the mail MIME part.

load(string $template, string|null $pkgHandle = null)

Load an email template from the /mail/ directory.

setBody(string|false $body)

Manually set the plain text body of a mail message (typically the body is set in the template + load method).

setSubject(string $subject)

Manually set the message's subject (typically the body is set in the template + load method).

string
getSubject()

Get the message subject.

string|false
getBody()

Get the plain text body.

string|false
getBodyHTML()

Get the html body.

setBodyHTML(string|false $html)

Manually set the HTML body of a mail message (typically the body is set in the template + load method).

enableMailResponseProcessing(MailImporter $importer, array $data)

No description

from(string $email, string|null $name = null)

Set the from address on the message.

to(string $email, string|null $name = null)

Add one or more "To" recipients to the message.

cc(string $email, string|null $name = null)

Add one or more "CC" recipients to the message.

bcc(string $email, string|null $name = null)

Add one or more "BCC" recipients to the message.

replyto(string $email, string|null $name = null)

Sets the Reply-To addresses of the message.

setTesting(bool $testing)

Set the testing state (if true the email logging never occurs and sending errors will throw an exception).

bool
getTesting()

Retrieve the testing state.

$this
setIsThrowOnFailure(mixed $throwOnFailure)

Should an exception be thrown if the delivery fails (if false, the sendMail() method will simply return false on failure).

bool
isThrowOnFailure()

Should an exception be thrown if the delivery fails (if false, the sendMail() method will simply return false on failure).

setAdditionalHeaders(array $headers)

Set additional message headers.

bool
sendMail(bool $resetData = true)

Sends the email.

static 
getMailerObject() deprecated

No description

string
generateEmailStrings(array $arr)

Convert a list of email addresses to a string.

Part|null
buildTextPart()

Get the MIME part for the plain text body (if available).

bool
isInlineAttachment(Part $attachment)

Determine if an attachment should be used as an inline attachment associated to the HTML body.

Part|null
buildHtmlPart()

Get the MIME part for the plain text body (if available).

Details

__construct(Application $app, TransportInterface $transport)

Initialize the instance.

Parameters

Application $app

the application instance

TransportInterface $transport

the transport to be used to delivery the messages

reset()

Clean up the instance of this object (reset the class scope variables).

addParameter(string $key, mixed $val)

Adds a parameter for the mail template.

Parameters

string $key

the name of the parameter

mixed $val

the value of the parameter

addAttachment(File $file)

Add a File entity as an attachment of the message.

Parameters

File $file

The file to attach to the message

addAttachmentWithHeaders(File $file, array $headers)

Add a File entity as an attachment of the message, specifying the headers of the mail MIME part.

Parameters

File $file

The file to attach to the message

array $headers

Additional headers fo the MIME part. Valid values are:

  • filename: The name to give to the attachment (it will be used as the filename part of the Content-Disposition header) [default: the filename of the File instance]
  • mimetype: the main value of the Content-Type header [default: the content type of the file]
  • disposition: the main value of the Content-Disposition header [default: attachment]
  • encoding: the value of the Content-Transfer-Encoding header [default: base64]
  • charset: the charset value of the Content-Type header
  • boundary: the boundary value of the Content-Type header
  • id: the value of the Content-ID header (without angular brackets)
  • description: the value of the Content-Description header
  • location: the value of the Content-Location header
  • language: the value of the Content-Language header

addRawAttachment(string $content, string $filename, string $mimetype = 'application/octet-stream')

Add a mail attachment by specifying its raw binary data.

Parameters

string $content

The binary data of the attachemt

string $filename

The name to give to the attachment (it will be used as the filename part of the Content-Disposition header)

string $mimetype

The MIME type of the attachment (it will be the main value of the Content-Type header)

addRawAttachmentWithHeaders(string $content, string $filename, array $headers = [])

Add a mail attachment by specifying its raw binary data, specifying the headers of the mail MIME part.

Parameters

string $content

The binary data of the attachemt

string $filename

The name to give to the attachment (it will be used as the filename part of the Content-Disposition header)

array $headers

Additional headers fo the MIME part. Valid values are:

  • mimetype: the main value of the Content-Type header [default: application/octet-stream]
  • disposition: the main value of the Content-Disposition header [default: attachment]
  • encoding: the value of the Content-Transfer-Encoding header [default: base64]
  • charset: the charset value of the Content-Type header
  • boundary: the boundary value of the Content-Type header
  • id: the value of the Content-ID header (without angular brackets)
  • description: the value of the Content-Description header
  • location: the value of the Content-Location header
  • language: the value of the Content-Language header

load(string $template, string|null $pkgHandle = null)

Load an email template from the /mail/ directory.

Parameters

string $template

The template to load

string|null $pkgHandle

The handle of the package associated to the template

setBody(string|false $body)

Manually set the plain text body of a mail message (typically the body is set in the template + load method).

Parameters

string|false $body

Set the text body (false to not use a plain text body)

setSubject(string $subject)

Manually set the message's subject (typically the body is set in the template + load method).

Parameters

string $subject

string getSubject()

Get the message subject.

Return Value

string

string|false getBody()

Get the plain text body.

Return Value

string|false

string|false getBodyHTML()

Get the html body.

Return Value

string|false

setBodyHTML(string|false $html)

Manually set the HTML body of a mail message (typically the body is set in the template + load method).

Parameters

string|false $html

Set the html body (false to not use an HTML body)

enableMailResponseProcessing(MailImporter $importer, array $data)

No description

Parameters

MailImporter $importer
array $data

from(string $email, string|null $name = null)

Set the from address on the message.

Parameters

string $email
string|null $name

to(string $email, string|null $name = null)

Add one or more "To" recipients to the message.

Parameters

string $email

(separate multiple email addresses with commas)

string|null $name

The name to associate to the email address

cc(string $email, string|null $name = null)

Add one or more "CC" recipients to the message.

Parameters

string $email

(separate multiple email addresses with commas)

string|null $name

The name to associate to the email address

bcc(string $email, string|null $name = null)

Add one or more "BCC" recipients to the message.

Parameters

string $email

(separate multiple email addresses with commas)

string|null $name

The name to associate to the email address

replyto(string $email, string|null $name = null)

Sets the Reply-To addresses of the message.

Parameters

string $email

(separate multiple email addresses with commas)

string|null $name

The name to associate to the email address

setTesting(bool $testing)

Set the testing state (if true the email logging never occurs and sending errors will throw an exception).

Parameters

bool $testing

bool getTesting()

Retrieve the testing state.

Return Value

bool

$this setIsThrowOnFailure(mixed $throwOnFailure)

Should an exception be thrown if the delivery fails (if false, the sendMail() method will simply return false on failure).

Parameters

mixed $throwOnFailure

Return Value

$this

bool isThrowOnFailure()

Should an exception be thrown if the delivery fails (if false, the sendMail() method will simply return false on failure).

Return Value

bool

setAdditionalHeaders(array $headers)

Set additional message headers.

Parameters

array $headers

bool sendMail(bool $resetData = true)

Sends the email.

Parameters

bool $resetData

Whether or not to reset the service to its default when this method is done

Return Value

bool

Returns true upon success, or false if the delivery fails and if the service is not in "testing" state and throwOnFailure is false

Exceptions

Exception

Throws an exception if the delivery fails and if the service is in "testing" state or throwOnFailure is true

static getMailerObject() deprecated

deprecated To get the mail transport, call \Core::make(\Zend\Mail\Transport\TransportInterface::class)

No description

protected string generateEmailStrings(array $arr)

Convert a list of email addresses to a string.

Parameters

array $arr

Return Value

string

protected Part|null buildTextPart()

Get the MIME part for the plain text body (if available).

Return Value

Part|null

protected bool isInlineAttachment(Part $attachment)

Determine if an attachment should be used as an inline attachment associated to the HTML body.

Parameters

Part $attachment

Return Value

bool

protected Part|null buildHtmlPart()

Get the MIME part for the plain text body (if available).

Return Value

Part|null