Interface yii\mail\MessageInterface

Implemented byyii\mail\BaseMessage, yii\swiftmailer\Message
Available since version2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/mail/MessageInterface.php

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('[email protected]')
    ->setTo($form->email)
    ->setSubject($form->subject)
    ->setTextBody('Plain text content')
    ->setHtmlBody('<b>HTML content</b>')
    ->send();

See also yii\mail\MailerInterface.

Public Methods

Hide inherited methods

MethodDescriptionDefined By
attach() Attaches existing file to the email message. yii\mail\MessageInterface
attachContent() Attach specified content as file for the email message. yii\mail\MessageInterface
embed() Attach a file and return it's CID source. yii\mail\MessageInterface
embedContent() Attach a content as file and return it's CID source. yii\mail\MessageInterface
getBcc() Returns the Bcc (hidden copy receiver) addresses of this message. yii\mail\MessageInterface
getCc() Returns the Cc (additional copy receiver) addresses of this message. yii\mail\MessageInterface
getCharset() Returns the character set of this message. yii\mail\MessageInterface
getFrom() Returns the message sender. yii\mail\MessageInterface
getReplyTo() Returns the reply-to address of this message. yii\mail\MessageInterface
getSubject() Returns the message subject. yii\mail\MessageInterface
getTo() Returns the message recipient(s). yii\mail\MessageInterface
send() Sends this email message. yii\mail\MessageInterface
setBcc() Sets the Bcc (hidden copy receiver) addresses of this message. yii\mail\MessageInterface
setCc() Sets the Cc (additional copy receiver) addresses of this message. yii\mail\MessageInterface
setCharset() Sets the character set of this message. yii\mail\MessageInterface
setFrom() Sets the message sender. yii\mail\MessageInterface
setHtmlBody() Sets message HTML content. yii\mail\MessageInterface
setReplyTo() Sets the reply-to address of this message. yii\mail\MessageInterface
setSubject() Sets the message subject. yii\mail\MessageInterface
setTextBody() Sets message plain text content. yii\mail\MessageInterface
setTo() Sets the message recipient(s). yii\mail\MessageInterface
toString() Returns string representation of this message. yii\mail\MessageInterface

Method Details

attach() public method

Attaches existing file to the email message.

$this attach$fileName, array $options = [] )
$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.
return $this

Self reference.

attachContent() public method

Attach specified content as file for the email message.

$this attachContent$content, array $options = [] )
$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.
return $this

Self reference.

embed() public method

Attach a file and return it's CID source.

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

string embed$fileName, array $options = [] )
$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.
return string

Attachment CID.

embedContent() public method

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.

string embedContent$content, array $options = [] )
$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.
return string

Attachment CID.

getBcc() public method

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

array getBcc( )
return array

The Bcc (hidden copy receiver) addresses of this message.

getCc() public method

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

array getCc( )
return array

The Cc (additional copy receiver) addresses of this message.

getCharset() public method

Returns the character set of this message.

string getCharset( )
return string

The character set of this message.

getFrom() public method

Returns the message sender.

string getFrom( )
return string

The sender

getReplyTo() public method

Returns the reply-to address of this message.

string getReplyTo( )
return string

The reply-to address of this message.

getSubject() public method

Returns the message subject.

string getSubject( )
return string

The message subject

getTo() public method

Returns the message recipient(s).

array getTo( )
return array

The message recipients

send() public method

Sends this email message.

boolean send( \yii\mail\MailerInterface $mailer null )
$mailer yii\mail\MailerInterface

The mailer that should be used to send this message. If null, the "mail" application component will be used instead.

return boolean

Whether this message is sent successfully.

setBcc() public method

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

$this setBcc$bcc )
$bcc string|array

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 $this

Self reference.

setCc() public method

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

$this setCc$cc )
$cc string|array

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 $this

Self reference.

setCharset() public method

Sets the character set of this message.

$this setCharset$charset )
$charset string

Character set name.

return $this

Self reference.

setFrom() public method

Sets the message sender.

$this setFrom$from )
$from string|array

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 $this

Self reference.

setHtmlBody() public method

Sets message HTML content.

$this setHtmlBody$html )
$html string

Message HTML content.

return $this

Self reference.

setReplyTo() public method

Sets the reply-to address of this message.

$this setReplyTo$replyTo )
$replyTo string|array

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 $this

Self reference.

setSubject() public method

Sets the message subject.

$this setSubject$subject )
$subject string

Message subject

return $this

Self reference.

setTextBody() public method

Sets message plain text content.

$this setTextBody$text )
$text string

Message plain text content.

return $this

Self reference.

setTo() public method

Sets the message recipient(s).

$this setTo$to )
$to string|array

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 $this

Self reference.

toString() public method

Returns string representation of this message.

string toString( )
return string

The string representation of this message.