MessageInterface
in
MessageInterface is the interface that should be implemented by mail message classes.
A message represents the settings and content of an email, such as the sender, recipient, subject, body, etc.
Messages are sent by a [[\yii\mail\MailerInterface|mailer]], like the following,
Yii::$app->mailer->compose()
->setFrom('from@domain.com')
->setTo($form->email)
->setSubject($form->subject)
->setTextBody('Plain text content')
->setHtmlBody('<b>HTML content</b>')
->send();
Tags
Table of Contents
Methods
- attach() : $this
- Attaches existing file to the email message.
- attachContent() : $this
- Attach specified content as file for the email message.
- embed() : string
- Attach a file and return it's CID source.
- embedContent() : string
- Attach a content as file and return it's CID source.
- getBcc() : string|array<string|int, mixed>
- Returns the Bcc (hidden copy receiver) addresses of this message.
- getCc() : string|array<string|int, mixed>
- Returns the Cc (additional copy receiver) addresses of this message.
- getCharset() : string
- Returns the character set of this message.
- getFrom() : string|array<string|int, mixed>
- Returns the message sender.
- getReplyTo() : string|array<string|int, mixed>
- Returns the reply-to address of this message.
- getSubject() : string
- Returns the message subject.
- getTo() : string|array<string|int, mixed>
- Returns the message recipient(s).
- send() : bool
- Sends this email message.
- setBcc() : $this
- Sets the Bcc (hidden copy receiver) addresses of this message.
- setCc() : $this
- Sets the Cc (additional copy receiver) addresses of this message.
- setCharset() : $this
- Sets the character set of this message.
- setFrom() : $this
- Sets the message sender.
- setHtmlBody() : $this
- Sets message HTML content.
- setReplyTo() : $this
- Sets the reply-to address of this message.
- setSubject() : $this
- Sets the message subject.
- setTextBody() : $this
- Sets message plain text content.
- setTo() : $this
- Sets the message recipient(s).
- toString() : string
- Returns string representation of this message.
Methods
attach()
Attaches existing file to the email message.
public
attach(string $fileName[, array<string|int, mixed> $options = [] ]) : $this
Parameters
- $fileName : string
-
full file name
- $options : array<string|int, mixed> = []
-
options for embed file. Valid options are:
- fileName: name, which should be used to attach file.
- contentType: attached file MIME type.
Return values
$this —self reference.
attachContent()
Attach specified content as file for the email message.
public
attachContent(string $content[, array<string|int, mixed> $options = [] ]) : $this
Parameters
- $content : string
-
attachment file content.
- $options : array<string|int, mixed> = []
-
options for embed file. Valid options are:
- fileName: name, which should be used to attach file.
- contentType: attached file MIME type.
Return values
$this —self reference.
embed()
Attach a file and return it's CID source.
public
embed(string $fileName[, array<string|int, mixed> $options = [] ]) : string
This method should be used when embedding images or other data in a message.
Parameters
- $fileName : string
-
file name.
- $options : array<string|int, mixed> = []
-
options for embed file. Valid options are:
- fileName: name, which should be used to attach file.
- contentType: attached file MIME type.
Return values
string —attachment CID.
embedContent()
Attach a content as file and return it's CID source.
public
embedContent(string $content[, array<string|int, mixed> $options = [] ]) : string
This method should be used when embedding images or other data in a message.
Parameters
- $content : string
-
attachment file content.
- $options : array<string|int, mixed> = []
-
options for embed file. Valid options are:
- fileName: name, which should be used to attach file.
- contentType: attached file MIME type.
Return values
string —attachment CID.
getBcc()
Returns the Bcc (hidden copy receiver) addresses of this message.
public
getBcc() : string|array<string|int, mixed>
Return values
string|array<string|int, mixed> —the Bcc (hidden copy receiver) addresses of this message.
getCc()
Returns the Cc (additional copy receiver) addresses of this message.
public
getCc() : string|array<string|int, mixed>
Return values
string|array<string|int, mixed> —the Cc (additional copy receiver) addresses of this message.
getCharset()
Returns the character set of this message.
public
getCharset() : string
Return values
string —the character set of this message.
getFrom()
Returns the message sender.
public
getFrom() : string|array<string|int, mixed>
Return values
string|array<string|int, mixed> —the sender
getReplyTo()
Returns the reply-to address of this message.
public
getReplyTo() : string|array<string|int, mixed>
Return values
string|array<string|int, mixed> —the reply-to address of this message.
getSubject()
Returns the message subject.
public
getSubject() : string
Return values
string —the message subject
getTo()
Returns the message recipient(s).
public
getTo() : string|array<string|int, mixed>
Return values
string|array<string|int, mixed> —the message recipients
send()
Sends this email message.
public
send([MailerInterface|null $mailer = null ]) : bool
Parameters
- $mailer : MailerInterface|null = null
-
the mailer that should be used to send this message. If null, the "mailer" application component will be used instead.
Return values
bool —whether this message is sent successfully.
setBcc()
Sets the Bcc (hidden copy receiver) addresses of this message.
public
setBcc(string|array<string|int, mixed> $bcc) : $this
Parameters
- $bcc : string|array<string|int, mixed>
-
hidden copy receiver email address. 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]
.
Return values
$this —self reference.
setCc()
Sets the Cc (additional copy receiver) addresses of this message.
public
setCc(string|array<string|int, mixed> $cc) : $this
Parameters
- $cc : string|array<string|int, mixed>
-
copy receiver email address. 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]
.
Return values
$this —self reference.
setCharset()
Sets the character set of this message.
public
setCharset(string $charset) : $this
Parameters
- $charset : string
-
character set name.
Return values
$this —self reference.
setFrom()
Sets the message sender.
public
setFrom(string|array<string|int, mixed> $from) : $this
Parameters
- $from : string|array<string|int, mixed>
-
sender email address. 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]
.
Return values
$this —self reference.
setHtmlBody()
Sets message HTML content.
public
setHtmlBody(string $html) : $this
Parameters
- $html : string
-
message HTML content.
Return values
$this —self reference.
setReplyTo()
Sets the reply-to address of this message.
public
setReplyTo(string|array<string|int, mixed> $replyTo) : $this
Parameters
- $replyTo : string|array<string|int, mixed>
-
the reply-to address. You may pass an array of addresses if this message should be replied to multiple people. You may also specify reply-to name in addition to email address using format:
[email => name]
.
Return values
$this —self reference.
setSubject()
Sets the message subject.
public
setSubject(string $subject) : $this
Parameters
- $subject : string
-
message subject
Return values
$this —self reference.
setTextBody()
Sets message plain text content.
public
setTextBody(string $text) : $this
Parameters
- $text : string
-
message plain text content.
Return values
$this —self reference.
setTo()
Sets the message recipient(s).
public
setTo(string|array<string|int, mixed> $to) : $this
Parameters
- $to : string|array<string|int, mixed>
-
receiver email address. 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]
.
Return values
$this —self reference.
toString()
Returns string representation of this message.
public
toString() : string
Return values
string —the string representation of this message.