Skip to content

Message ​

Type
Class
Namespace
craft\mail
Inherits
craft\mail\Message » yii\swiftmailer\Message » yii\mail\BaseMessage » yii\base\BaseObject
Implements
yii\base\Configurable, yii\mail\MessageInterface
Since
3.0.0

Represents an email message.

View source

Public Properties ​

PropertyDescription
bccstring, array – The Bcc (hidden copy receiver) addresses of this message.
ccstring, array – The Cc (additional copy receiver) addresses of this message.
charsetstring – The character set of this message.
error\craft\mail\Swift_TransportException, null – The caught error object, if the message failed to send
fromstring, array – The sender
headersarray – Headers in format: [name => value].
htmlBodystring – Message HTML content.
keystring, null – The key of the message that should be loaded
languagestring, null – The language that the email should be sent in, based on the first craft\elements\User model passed into setTo() with a preferred language
maileryii\mail\MailerInterface, null – The mailer instance that created this message.
priorityinteger – Priority value as integer in range: 1..5, where 1 is the highest priority and 5 is the lowest.
readReceiptTostring – Receipt receive email addresses.
replyTostring, array – The reply-to address of this message.
returnPathstring – The bounce email address.
signaturearray, callable, \Swift_Signer – Signature specification.
subjectstring – The message subject
swiftMessage\Swift_Message – Swift message instance.
textBodystring – Message plain text content.
tostring, array – The message recipients
variablesarray, null – Any variables that should be applied to the template when it is rendered

error ​

Type
\craft\mail\Swift_TransportException, null
Default value
null

The caught error object, if the message failed to send

View source

key ​

Type
string, null
Default value
null

The key of the message that should be loaded

View source

language ​

Type
string, null
Default value
null

The language that the email should be sent in, based on the first craft\elements\User model passed into setTo() with a preferred language

View source

variables ​

Type
array, null
Default value
null

Any variables that should be applied to the template when it is rendered

View source

Public Methods ​

MethodDescription
__call()Calls the named method which is not a class method.
__clone()This method is called after the object is created by cloning an existing one.
__construct()Constructor.
__get()Returns the value of an object property.
__isset()Checks if a property is set, i.e. defined and not null.
__set()Sets value of an object property.
__toString()PHP magic method that returns the string representation of this object.
__unset()Sets an object property to null.
addHeader()Adds custom header value to the message.
addSignature()Adds message signature.
attach()Attaches existing file to the email message.
attachContent()Attach specified content as file for the email message.
canGetProperty()Returns a value indicating whether a property can be read.
canSetProperty()Returns a value indicating whether a property can be set.
className()Returns the fully qualified name of this class.
embed()Attach a file and return it's CID source.
embedContent()Attach a content as file and return it's CID source.
getBcc()Returns the Bcc (hidden copy receiver) addresses of this message.
getCc()Returns the Cc (additional copy receiver) addresses of this message.
getCharset()Returns the character set of this message.
getFrom()Returns the message sender.
getHeader()Returns all values for the specified header.
getMailer()returns mailer instance.
getPriority()Returns the priority of this message.
getReadReceiptTo()Get the addresses to which a read-receipt will be sent.
getReplyTo()Returns the reply-to address of this message.
getReturnPath()Returns the return-path (the bounce address) of this message.
getSubject()Returns the message subject.
getSwiftMessage()
getTo()Returns the message recipient(s).
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined.
init()Initializes the object.
send()Sends this email message.
setBcc()Sets the BCC (hidden copy receiver) addresses of this message.
setCc()Sets the CC (additional copy receiver) addresses of this message.
setCharset()Sets the character set of this message.
setFrom()Sets the message sender.
setHeader()Sets custom header value to the message.
setHeaders()Sets custom header values to the message.
setHtmlBody()Sets message HTML content.
setPriority()Set the priority of this message.
setReadReceiptTo()Sets the ask for a delivery receipt from the recipient to be sent to $addresses.
setReplyTo()Sets the Reply-To email.
setReturnPath()Set the return-path (the bounce address) of this message.
setSignature()Sets message signature
setSubject()Sets the message subject.
setTextBody()Sets message plain text content.
setTo()Sets the message recipient(s).
toString()Returns string representation of this message.

setBcc() ​

Sets the BCC (hidden copy receiver) addresses of this message.

View source

Arguments ​

  • $bcc (string, array, craft\elements\User, craft\elements\User[]) – The hidden copied receiver’s email address, or their user model(s). You may pass an array of addresses if multiple recipients should receive this message. You may also specify receiver name in addition to email address using format: [email => name].

Returns ​

static – Self reference

setCc() ​

Sets the CC (additional copy receiver) addresses of this message.

View source

Arguments ​

  • $cc (string, array, craft\elements\User, craft\elements\User[]) – The copied receiver’s email address, or their user model(s). You may pass an array of addresses if multiple recipients should receive this message. You may also specify receiver name in addition to email address using format: [email => name].

Returns ​

static – Self reference

setFrom() ​

Sets the message sender.

View source

Arguments ​

  • $from (string, array, craft\elements\User, craft\elements\User[]) – The sender’s email address, or their user model(s). You may pass an array of addresses if this message is from multiple people. You may also specify sender name in addition to email address using format: [email => name].

Returns ​

static – Self reference

setReplyTo() ​

Since
3.4.0

Sets the Reply-To email.

View source

Arguments ​

  • $replyTo (string, array, craft\elements\User, craft\elements\User[]) – The Reply-To email address, or their user model(s). You may pass an array of addresses if this message is from multiple people. You may also specify Reply-To name in addition to email address using format: [email => name].

Returns ​

static – Self reference

setTo() ​

Sets the message recipient(s).

View source

Arguments ​

  • $to (string, array, craft\elements\User, craft\elements\User[]) – The receiver’s email address, or their user model(s). You may pass an array of addresses if multiple recipients should receive this message. You may also specify receiver name in addition to email address using format: [email => name].

Returns ​

static – Self reference

Protected Methods ​

MethodDescription
createSwiftMessage()Creates the Swift email message instance.
createSwiftSigner()Creates signer from it's configuration.
setBody()Sets the message body.