MessageInterface
API reference › yii › mail › MessageInterface
Implemented by 1 type
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 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();See also: MailerInterface.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
attach() abstract | Attaches existing file to the email message. | MessageInterface |
attachContent() abstract | Attach specified content as file for the email message. | MessageInterface |
embed() abstract | Attach a file and return it’s CID source. | MessageInterface |
embedContent() abstract | Attach a content as file and return it’s CID source. | MessageInterface |
getBcc() abstract | Returns the Bcc (hidden copy receiver) addresses of this message. | MessageInterface |
getCc() abstract | Returns the Cc (additional copy receiver) addresses of this message. | MessageInterface |
getCharset() abstract | Returns the character set of this message. | MessageInterface |
getFrom() abstract | Returns the message sender. | MessageInterface |
getReplyTo() abstract | Returns the reply-to address of this message. | MessageInterface |
getSubject() abstract | Returns the message subject. | MessageInterface |
getTo() abstract | Returns the message recipient(s). | MessageInterface |
send() abstract | Sends this email message. | MessageInterface |
setBcc() abstract | Sets the Bcc (hidden copy receiver) addresses of this message. | MessageInterface |
setCc() abstract | Sets the Cc (additional copy receiver) addresses of this message. | MessageInterface |
setCharset() abstract | Sets the character set of this message. | MessageInterface |
setFrom() abstract | Sets the message sender. | MessageInterface |
setHtmlBody() abstract | Sets message HTML content. | MessageInterface |
setReplyTo() abstract | Sets the reply-to address of this message. | MessageInterface |
setSubject() abstract | Sets the message subject. | MessageInterface |
setTextBody() abstract | Sets message plain text content. | MessageInterface |
setTo() abstract | Sets the message recipient(s). | MessageInterface |
toString() abstract | Returns string representation of this message. | MessageInterface |
Method details
Section titled “Method details”attach()
Section titled “attach() ”abstract public function attach(string $fileName, array $options = []): $thisAttaches existing file to the email message.
Parameters
| Parameter | Type | Description |
|---|---|---|
$fileName | string | Full file name |
$options | array | Options for embed file. Valid options are: - fileName: name, which should be used to attach file. - contentType: attached file MIME type. |
Returns
$this: Self reference.
attachContent()
Section titled “attachContent() ”abstract public function attachContent(string $content, array $options = []): $thisAttach specified content as file for the email message.
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string | Attachment file content. |
$options | array | Options for embed file. Valid options are: - fileName: name, which should be used to attach file. - contentType: attached file MIME type. |
Returns
$this: Self reference.
embed()
Section titled “embed() ”abstract public function embed(string $fileName, array $options = []): stringAttach a file and return it’s CID source.
This method should be used when embedding images or other data in a message.
Parameters
| Parameter | Type | Description |
|---|---|---|
$fileName | string | File name. |
$options | array | Options for embed file. Valid options are: - fileName: name, which should be used to attach file. - contentType: attached file MIME type. |
Returns
string: Attachment CID.
embedContent()
Section titled “embedContent() ”abstract public function embedContent(string $content, array $options = []): stringAttach a content as file and return it’s CID source.
This method should be used when embedding images or other data in a message.
Parameters
| Parameter | Type | Description |
|---|---|---|
$content | string | Attachment file content. |
$options | array | Options for embed file. Valid options are: - fileName: name, which should be used to attach file. - contentType: attached file MIME type. |
Returns
string: Attachment CID.
getBcc()
Section titled “getBcc() ”abstract public function getBcc(): string|arrayReturns the Bcc (hidden copy receiver) addresses of this message.
Returns
string|array: The Bcc (hidden copy receiver) addresses of this message.
getCc()
Section titled “getCc() ”abstract public function getCc(): string|arrayReturns the Cc (additional copy receiver) addresses of this message.
Returns
string|array: The Cc (additional copy receiver) addresses of this message.
getCharset()
Section titled “getCharset() ”abstract public function getCharset(): stringReturns the character set of this message.
Returns
string: The character set of this message.
getFrom()
Section titled “getFrom() ”abstract public function getFrom(): string|arrayReturns the message sender.
Returns
string|array: The sender
getReplyTo()
Section titled “getReplyTo() ”abstract public function getReplyTo(): string|arrayReturns the reply-to address of this message.
Returns
string|array: The reply-to address of this message.
getSubject()
Section titled “getSubject() ”abstract public function getSubject(): stringReturns the message subject.
Returns
string: The message subject
getTo()
Section titled “getTo() ”abstract public function getTo(): string|arrayReturns the message recipient(s).
Returns
string|array: The message recipients
send()
Section titled “send() ”abstract public function send(yii\mail\MailerInterface|null $mailer = null): boolSends this email message.
Parameters
| Parameter | Type | Description |
|---|---|---|
$mailer | MailerInterface| | The mailer that should be used to send this message. If null, the “mailer” application component will be used instead. |
Returns
bool: Whether this message is sent successfully.
setBcc()
Section titled “setBcc() ”abstract public function setBcc(string|array $bcc): $thisSets the Bcc (hidden copy receiver) addresses of this message.
Parameters
| Parameter | Type | Description |
|---|---|---|
$bcc | string| | 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]. |
Returns
$this: Self reference.
setCc()
Section titled “setCc() ”abstract public function setCc(string|array $cc): $thisSets the Cc (additional copy receiver) addresses of this message.
Parameters
| Parameter | Type | Description |
|---|---|---|
$cc | string| | 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]. |
Returns
$this: Self reference.
setCharset()
Section titled “setCharset() ”abstract public function setCharset(string $charset): $thisSets the character set of this message.
Parameters
| Parameter | Type | Description |
|---|---|---|
$charset | string | Character set name. |
Returns
$this: Self reference.
setFrom()
Section titled “setFrom() ”abstract public function setFrom(string|array $from): $thisSets the message sender.
Parameters
| Parameter | Type | Description |
|---|---|---|
$from | string| | 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]. |
Returns
$this: Self reference.
setHtmlBody()
Section titled “setHtmlBody() ”abstract public function setHtmlBody(string $html): $thisSets message HTML content.
Parameters
| Parameter | Type | Description |
|---|---|---|
$html | string | Message HTML content. |
Returns
$this: Self reference.
setReplyTo()
Section titled “setReplyTo() ”abstract public function setReplyTo(string|array $replyTo): $thisSets the reply-to address of this message.
Parameters
| Parameter | Type | Description |
|---|---|---|
$replyTo | string| | 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]. |
Returns
$this: Self reference.
setSubject()
Section titled “setSubject() ”abstract public function setSubject(string $subject): $thisSets the message subject.
Parameters
| Parameter | Type | Description |
|---|---|---|
$subject | string | Message subject |
Returns
$this: Self reference.
setTextBody()
Section titled “setTextBody() ”abstract public function setTextBody(string $text): $thisSets message plain text content.
Parameters
| Parameter | Type | Description |
|---|---|---|
$text | string | Message plain text content. |
Returns
$this: Self reference.
setTo()
Section titled “setTo() ”abstract public function setTo(string|array $to): $thisSets the message recipient(s).
Parameters
| Parameter | Type | Description |
|---|---|---|
$to | string| | 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]. |
Returns
$this: Self reference.
toString()
Section titled “toString() ”abstract public function toString(): stringReturns string representation of this message.
Returns
string: The string representation of this message.