Skip to content
PHP Ecosystem
Explore

MessageInterface

API reference › yii › mail › MessageInterface

interfaceyii\mail\MessageInterface
Since2.0
Sourceframework/mail/MessageInterface.php
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.

MethodDescriptionDefined by
attach() abstractAttaches existing file to the email message.MessageInterface
attachContent() abstractAttach specified content as file for the email message.MessageInterface
embed() abstractAttach a file and return it’s CID source.MessageInterface
embedContent() abstractAttach a content as file and return it’s CID source.MessageInterface
getBcc() abstractReturns the Bcc (hidden copy receiver) addresses of this message.MessageInterface
getCc() abstractReturns the Cc (additional copy receiver) addresses of this message.MessageInterface
getCharset() abstractReturns the character set of this message.MessageInterface
getFrom() abstractReturns the message sender.MessageInterface
getReplyTo() abstractReturns the reply-to address of this message.MessageInterface
getSubject() abstractReturns the message subject.MessageInterface
getTo() abstractReturns the message recipient(s).MessageInterface
send() abstractSends this email message.MessageInterface
setBcc() abstractSets the Bcc (hidden copy receiver) addresses of this message.MessageInterface
setCc() abstractSets the Cc (additional copy receiver) addresses of this message.MessageInterface
setCharset() abstractSets the character set of this message.MessageInterface
setFrom() abstractSets the message sender.MessageInterface
setHtmlBody() abstractSets message HTML content.MessageInterface
setReplyTo() abstractSets the reply-to address of this message.MessageInterface
setSubject() abstractSets the message subject.MessageInterface
setTextBody() abstractSets message plain text content.MessageInterface
setTo() abstractSets the message recipient(s).MessageInterface
toString() abstractReturns string representation of this message.MessageInterface
abstract public function attach(string $fileName, array $options = []): $this

Attaches existing file to the email message.

Parameters

ParameterTypeDescription
$fileNamestringFull file name
$optionsarrayOptions for embed file. Valid options are: - fileName: name, which should be used to attach file. - contentType: attached file MIME type.

Returns

$this: Self reference.

abstract public function attachContent(string $content, array $options = []): $this

Attach specified content as file for the email message.

Parameters

ParameterTypeDescription
$contentstringAttachment file content.
$optionsarrayOptions for embed file. Valid options are: - fileName: name, which should be used to attach file. - contentType: attached file MIME type.

Returns

$this: Self reference.

abstract public function embed(string $fileName, array $options = []): string

Attach a file and return it’s CID source.

This method should be used when embedding images or other data in a message.

Parameters

ParameterTypeDescription
$fileNamestringFile name.
$optionsarrayOptions for embed file. Valid options are: - fileName: name, which should be used to attach file. - contentType: attached file MIME type.

Returns

string: Attachment CID.

abstract public function embedContent(string $content, array $options = []): string

Attach 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

ParameterTypeDescription
$contentstringAttachment file content.
$optionsarrayOptions for embed file. Valid options are: - fileName: name, which should be used to attach file. - contentType: attached file MIME type.

Returns

string: Attachment CID.

abstract public function getBcc(): string|array

Returns the Bcc (hidden copy receiver) addresses of this message.

Returns

string|array: The Bcc (hidden copy receiver) addresses of this message.

abstract public function getCc(): string|array

Returns the Cc (additional copy receiver) addresses of this message.

Returns

string|array: The Cc (additional copy receiver) addresses of this message.

abstract public function getCharset(): string

Returns the character set of this message.

Returns

string: The character set of this message.

abstract public function getFrom(): string|array

Returns the message sender.

Returns

string|array: The sender

abstract public function getReplyTo(): string|array

Returns the reply-to address of this message.

Returns

string|array: The reply-to address of this message.

abstract public function getSubject(): string

Returns the message subject.

Returns

string: The message subject

abstract public function getTo(): string|array

Returns the message recipient(s).

Returns

string|array: The message recipients

abstract public function send(yii\mail\MailerInterface|null $mailer = null): bool

Sends this email message.

Parameters

ParameterTypeDescription
$mailerMailerInterface|nullThe 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.

abstract public function setBcc(string|array $bcc): $this

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

Parameters

ParameterTypeDescription
$bccstring|arrayHidden 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.

abstract public function setCc(string|array $cc): $this

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

Parameters

ParameterTypeDescription
$ccstring|arrayCopy 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.

abstract public function setCharset(string $charset): $this

Sets the character set of this message.

Parameters

ParameterTypeDescription
$charsetstringCharacter set name.

Returns

$this: Self reference.

abstract public function setFrom(string|array $from): $this

Sets the message sender.

Parameters

ParameterTypeDescription
$fromstring|arraySender 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.

abstract public function setHtmlBody(string $html): $this

Sets message HTML content.

Parameters

ParameterTypeDescription
$htmlstringMessage HTML content.

Returns

$this: Self reference.

abstract public function setReplyTo(string|array $replyTo): $this

Sets the reply-to address of this message.

Parameters

ParameterTypeDescription
$replyTostring|arrayThe 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.

abstract public function setSubject(string $subject): $this

Sets the message subject.

Parameters

ParameterTypeDescription
$subjectstringMessage subject

Returns

$this: Self reference.

abstract public function setTextBody(string $text): $this

Sets message plain text content.

Parameters

ParameterTypeDescription
$textstringMessage plain text content.

Returns

$this: Self reference.

abstract public function setTo(string|array $to): $this

Sets the message recipient(s).

Parameters

ParameterTypeDescription
$tostring|arrayReceiver 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.

abstract public function toString(): string

Returns string representation of this message.

Returns

string: The string representation of this message.