Interface yii\mail\MessageInterface
| Implemented by | yii\mail\BaseMessage |
|---|---|
| Available since version | 2.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('from@domain.com')
->setTo($form->email)
->setSubject($form->subject)
->setTextBody('Plain text content')
->setHtmlBody('<b>HTML content</b>')
->send();
See also yii\mail\MailerInterface.
Public Methods
| Method | Description | Defined 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
Attaches existing file to the email message.
| public abstract attach( string $fileName, array $options = [] ): $this | ||
| $fileName | string |
Full file name |
| $options | array |
Options for embed file. Valid options are:
|
| return | $this |
Self reference. |
|---|---|---|
public function attach($fileName, array $options = []);
Attach specified content as file for the email message.
| public abstract attachContent( string $content, array $options = [] ): $this | ||
| $content | string |
Attachment file content. |
| $options | array |
Options for embed file. Valid options are:
|
| return | $this |
Self reference. |
|---|---|---|
public function attachContent($content, array $options = []);
Attach a file and return it's CID source.
This method should be used when embedding images or other data in a message.
| public abstract embed( string $fileName, array $options = [] ): string | ||
| $fileName | string |
File name. |
| $options | array |
Options for embed file. Valid options are:
|
| return | string |
Attachment CID. |
|---|---|---|
public function embed($fileName, array $options = []);
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.
| public abstract embedContent( string $content, array $options = [] ): string | ||
| $content | string |
Attachment file content. |
| $options | array |
Options for embed file. Valid options are:
|
| return | string |
Attachment CID. |
|---|---|---|
public function embedContent($content, array $options = []);
Returns the Bcc (hidden copy receiver) addresses of this message.
| public abstract getBcc( ): string|array | ||
| return | string|array |
The Bcc (hidden copy receiver) addresses of this message. |
|---|---|---|
public function getBcc();
Returns the Cc (additional copy receiver) addresses of this message.
| public abstract getCc( ): string|array | ||
| return | string|array |
The Cc (additional copy receiver) addresses of this message. |
|---|---|---|
public function getCc();
Returns the character set of this message.
| public abstract getCharset( ): string | ||
| return | string |
The character set of this message. |
|---|---|---|
public function getCharset();
Returns the message sender.
| public abstract getFrom( ): string|array | ||
| return | string|array |
The sender |
|---|---|---|
public function getFrom();
Returns the reply-to address of this message.
| public abstract getReplyTo( ): string|array | ||
| return | string|array |
The reply-to address of this message. |
|---|---|---|
public function getReplyTo();
Returns the message subject.
| public abstract getSubject( ): string | ||
| return | string |
The message subject |
|---|---|---|
public function getSubject();
Returns the message recipient(s).
| public abstract getTo( ): string|array | ||
| return | string|array |
The message recipients |
|---|---|---|
public function getTo();
Sends this email message.
| public abstract send( yii\mail\MailerInterface|null $mailer = null ): boolean | ||
| $mailer | yii\mail\MailerInterface|null |
The mailer that should be used to send this message. If null, the "mailer" application component will be used instead. |
| return | boolean |
Whether this message is sent successfully. |
|---|---|---|
public function send(?MailerInterface $mailer = null);
Sets the Bcc (hidden copy receiver) addresses of this message.
| public abstract setBcc( string|array $bcc ): $this | ||
| $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:
|
| return | $this |
Self reference. |
|---|---|---|
public function setBcc($bcc);
Sets the Cc (additional copy receiver) addresses of this message.
| public abstract setCc( string|array $cc ): $this | ||
| $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:
|
| return | $this |
Self reference. |
|---|---|---|
public function setCc($cc);
Sets the character set of this message.
| public abstract setCharset( string $charset ): $this | ||
| $charset | string |
Character set name. |
| return | $this |
Self reference. |
|---|---|---|
public function setCharset($charset);
Sets the message sender.
| public abstract setFrom( string|array $from ): $this | ||
| $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:
|
| return | $this |
Self reference. |
|---|---|---|
public function setFrom($from);
Sets message HTML content.
| public abstract setHtmlBody( string $html ): $this | ||
| $html | string |
Message HTML content. |
| return | $this |
Self reference. |
|---|---|---|
public function setHtmlBody($html);
Sets the reply-to address of this message.
| public abstract setReplyTo( string|array $replyTo ): $this | ||
| $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:
|
| return | $this |
Self reference. |
|---|---|---|
public function setReplyTo($replyTo);
Sets the message subject.
| public abstract setSubject( string $subject ): $this | ||
| $subject | string |
Message subject |
| return | $this |
Self reference. |
|---|---|---|
public function setSubject($subject);
Sets message plain text content.
| public abstract setTextBody( string $text ): $this | ||
| $text | string |
Message plain text content. |
| return | $this |
Self reference. |
|---|---|---|
public function setTextBody($text);
Sets the message recipient(s).
| public abstract setTo( string|array $to ): $this | ||
| $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:
|
| return | $this |
Self reference. |
|---|---|---|
public function setTo($to);
Signup or Login in order to comment.