abstract class BaseMessage (View source)

Abstract base class for sending mail using the App Engine mail APIs.

Properties

protected $message
static protected $allowed_headers
static protected $extension_denylist
static protected $set_functions

Methods

send()

No description

getFunctionArray()

No description

__construct(array $options = null)

Construct an instance of Message.

addAttachment(string $filename, mixed $data, string $content_id = null)

Adds an attachment to the Message object.

addAttachmentArray() deprecated

Adds an array of attachments to the Message object.

addAttachmentsArray()

Adds an array of attachments to the Message object.

addHeader(string $key, string $value)

Adds a header pair to the mail object.

addHeaderArray()

Adds an array of headers to the mail object.

bool
checkValidAttachment(string $filename)

Checks that an attachment is valid.

bool
checkValidEmail(string $email)

Checks that an email is valid using the mailparse extension if available.

bool
checkValidHeader(string $key, string $value)

Check validity of a header pair.

clearAttachments()

Clear all attachments from the mail object.

clearHeaders()

Clear all headers from the mail object.

handleApplicationError()

Handles application errors generated by the RPC call.

setHtmlBody(string $text)

Sets HTML content for the email body.

setAmpHtmlBody(string $text)

Sets AMP HTML content for the email body. This field is optional. Setting AMP HTML body makes the email an AMP Email. Plain text or HTML may become fallback content depending on the email client used.

setReplyTo(string $email)

Sets a reply-to address for the mail object.

setSender(string $email)

Sets the sender for the mail object.

setSubject(string $subject)

Sets the subject for the mail object.

bool
setTextBody(string $text)

Sets plain text for the email body.

Details

abstract send()

abstract protected getFunctionArray()

__construct(array $options = null)

Construct an instance of Message.

Parameters

array $options Options for message content, key as per set_functions shown above, value to be set.

Exceptions

InvalidArgumentException If the options variable passed was not an array, if an invalid option was set in the options array, or if a value to be set by the options array was invalid.

addAttachment(string $filename, mixed $data, string $content_id = null)

Adds an attachment to the Message object.

Parameters

string $filename Filename of the attachment.
mixed $data File data of the attachment.
string $content_id Optional Content-ID header value of the attachment. Must be enclosed by angle brackets (<>).

Exceptions

InvalidArgumentException If the input is not an array or if the attachment type is invalid (i.e. the filename is not a string, or the file extension is denied).

addAttachmentArray() deprecated

deprecated

Adds an array of attachments to the Message object.

Exceptions

InvalidArgumentException If the input is not an array or if the attachment type is invalid (i.e. the filename is not a string, or the file extension is denied).

addAttachmentsArray()

Adds an array of attachments to the Message object.

Exceptions

InvalidArgumentException If the input is not an array or if the attachment type is invalid (i.e. the filename is not a string, or the file extension is denied).

addHeader(string $key, string $value)

Adds a header pair to the mail object.

Parameters

string $key Header name (from the allowlist) to be added.
string $value Header value to be added.

Exceptions

InvalidArgumentException If the header is not on the allowlist, or if the header is invalid (i.e. not a string).

addHeaderArray()

Adds an array of headers to the mail object.

Exceptions

InvalidArgumentException If the input is not an array, or if headers are not on the allowlist, or if a header is invalid (i.e. not a string).

protected bool checkValidAttachment(string $filename)

Checks that an attachment is valid.

Parameters

string $filename Filename of the attachment.

Return Value

bool True if successful, false otherwise.

protected bool checkValidEmail(string $email)

Checks that an email is valid using the mailparse extension if available.

Parameters

string $email The email to be validated.

Return Value

bool True if valid, false otherwise.

protected bool checkValidHeader(string $key, string $value)

Check validity of a header pair.

Parameters

string $key Header key.
string $value Header value.

Return Value

bool True if successful, false otherwise.

clearAttachments()

Clear all attachments from the mail object.

clearHeaders()

Clear all headers from the mail object.

protected handleApplicationError()

Handles application errors generated by the RPC call.

Exceptions

RuntimeException If there was an internal error or bad request.
InvalidArgumentException If there was an unauthorized sender, an invalid attachment type, or an invalid header name.
ApplicationError If the error is not one of the above.

setHtmlBody(string $text)

Sets HTML content for the email body.

Parameters

string $text HTML to add.

Exceptions

InvalidArgumentException If text is not a string.

setAmpHtmlBody(string $text)

Sets AMP HTML content for the email body. This field is optional. Setting AMP HTML body makes the email an AMP Email. Plain text or HTML may become fallback content depending on the email client used.

Parameters

string $text AMP HTML to add.

Exceptions

InvalidArgumentException If text is not a string.

setReplyTo(string $email)

Sets a reply-to address for the mail object.

Parameters

string $email Reply-to address.

Exceptions

InvalidArgumentException If the input reply-to address is an invalid email address.

setSender(string $email)

Sets the sender for the mail object.

Parameters

string $email Email of the sender.

Exceptions

InvalidArgumentException If the input sender is an invalid email address.

setSubject(string $subject)

Sets the subject for the mail object.

Parameters

string $subject Subject line.

Exceptions

InvalidArgumentException If subject line is not a string.

bool setTextBody(string $text)

Sets plain text for the email body.

Parameters

string $text Plain text to add.

Return Value

bool True if successful, false otherwise.

Exceptions

InvalidArgumentException If text is not a string.