class Message extends BaseMessage (View source)

Allows users to send mail using the App Engine mail APIs.

Properties

protected $message from BaseMessage
static protected $allowed_headers from BaseMessage
static protected $extension_denylist from BaseMessage
static protected $set_functions from BaseMessage

Methods

send()

Send the pre-formed email from the Message object.

getFunctionArray()

Returns the class variable $set_functions array, or the corresponding value in that array if a key is provided.

__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.

addBcc(mixed $emails)

Adds a "bcc" address, or array of addresses, to the mail object.

addCc(mixed $emails)

Adds a "cc" address, or array of addresses, to the mail object.

addTo(mixed $emails)

Adds a "to" address, or array of addresses, to the mail object.

clearBcc()

Clears all "bcc" addresses from the mail object.

clearCc()

Clears all "cc" addresses from the mail object.

clearReplyTo()

Clear reply-to address from the mail object.

clearTo()

Clears all "to" addresses from the mail object.

An
validEmailsArray($email_list, $err_str)

Checks that an email input is either: - An array, and each array member is a valid email - A single valid email string And subsequently returns an array of the valid emails.

Details

send()

Send the pre-formed email from the Message object.

Exceptions

InvalidArgumentException If a required field (sender, recipient [to, cc or bcc], subject, body [plain or html]) is missing, or if an ApplicationError was thrown by the RPC call due to an unauthorized sender, an invalid attachment type, or an invalid header name.
RuntimeException If an ApplicationError was thrown by the RPC call due to an internal error or bad request.
ApplicationError If there was an unknown error in the RPC call.

protected getFunctionArray()

Returns the class variable $set_functions array, or the corresponding value in that array if a key is provided.

__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.

addBcc(mixed $emails)

Adds a "bcc" address, or array of addresses, to the mail object.

Parameters

mixed $emails String email of individual recipient, or array of emails of recipients.

Exceptions

InvalidArgumentException If any of the input emails are not correctly formatted email addresses.

addCc(mixed $emails)

Adds a "cc" address, or array of addresses, to the mail object.

Parameters

mixed $emails String email of individual recipient, or array of emails of recipients.

Exceptions

InvalidArgumentException If any of the input emails are not correctly formatted email addresses.

addTo(mixed $emails)

Adds a "to" address, or array of addresses, to the mail object.

Parameters

mixed $emails String email of individual recipient, or array of emails of recipients.

Exceptions

InvalidArgumentException If any of the input emails are not correctly formatted email addresses.

clearBcc()

Clears all "bcc" addresses from the mail object.

clearCc()

Clears all "cc" addresses from the mail object.

clearReplyTo()

Clear reply-to address from the mail object.

clearTo()

Clears all "to" addresses from the mail object.

protected An validEmailsArray($email_list, $err_str)

Checks that an email input is either: - An array, and each array member is a valid email - A single valid email string And subsequently returns an array of the valid emails.

Parameters

$email_list
$err_str

Return Value

An array of emails.

Exceptions

InvalidArgumentException If any of the input emails are not correctly formatted email addresses.