PHP Interface yii\mail\MessageInterface

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('[email protected]') ->setTo($form->email) ->setSubject($form->subject) ->setTextBody('Plain text content') ->setHtmlBody('HTML content') ->send(); ~~~
See also: MailerInterface
Since: 2.0
Author: Paul Klimov ([email protected])
Show file Open project: yiisoft/yii2 Interface Usage Examples

Public Methods

Method Description
attach ( string $fileName, array $options = [] ) Attaches existing file to the email message.
attachContent ( string $content, array $options = [] ) Attach specified content as file for the email message.
embed ( string $fileName, array $options = [] ) : string Attach a file and return it's CID source.
embedContent ( string $content, array $options = [] ) : string Attach a content as file and return it's CID source.
getBcc ( ) : array Returns the Bcc (hidden copy receiver) addresses of this message.
getCc ( ) : array Returns the Cc (additional copy receiver) addresses of this message.
getCharset ( ) : string Returns the character set of this message.
getFrom ( ) : string Returns the message sender.
getReplyTo ( ) : string Returns the reply-to address of this message.
getSubject ( ) : string Returns the message subject.
getTo ( ) : array Returns the message recipient(s).
send ( yii\mail\MailerInterface $mailer = null ) : boolean Sends this email message.
setBcc ( string | array $bcc ) Sets the Bcc (hidden copy receiver) addresses of this message.
setCc ( string | array $cc ) Sets the Cc (additional copy receiver) addresses of this message.
setCharset ( string $charset ) Sets the character set of this message.
setFrom ( string | array $from ) Sets the message sender.
setHtmlBody ( string $html ) Sets message HTML content.
setReplyTo ( string | array $replyTo ) Sets the reply-to address of this message.
setSubject ( string $subject ) Sets the message subject.
setTextBody ( string $text ) Sets message plain text content.
setTo ( string | array $to ) Sets the message recipient(s).
toString ( ) : string Returns string representation of this message.

Method Details

attach() public method

Attaches existing file to the email message.
public attach ( string $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.

attachContent() public method

Attach specified content as file for the email message.
public attachContent ( string $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.

embed() public method

This method should be used when embedding images or other data in a message.
public embed ( string $fileName, array $options = [] ) : string
$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

This method should be used when embedding images or other data in a message.
public embedContent ( string $content, array $options = [] ) : string
$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.
public getBcc ( ) : array
return array the Bcc (hidden copy receiver) addresses of this message.

getCc() public method

Returns the Cc (additional copy receiver) addresses of this message.
public getCc ( ) : array
return array the Cc (additional copy receiver) addresses of this message.

getCharset() public method

Returns the character set of this message.
public getCharset ( ) : string
return string the character set of this message.

getFrom() public method

Returns the message sender.
public getFrom ( ) : string
return string the sender

getReplyTo() public method

Returns the reply-to address of this message.
public getReplyTo ( ) : string
return string the reply-to address of this message.

getSubject() public method

Returns the message subject.
public getSubject ( ) : string
return string the message subject

getTo() public method

Returns the message recipient(s).
public getTo ( ) : array
return array the message recipients

send() public method

Sends this email message.
public send ( yii\mail\MailerInterface $mailer = null ) : boolean
$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.
public setBcc ( string | array $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]`.

setCc() public method

Sets the Cc (additional copy receiver) addresses of this message.
public setCc ( string | array $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]`.

setCharset() public method

Sets the character set of this message.
public setCharset ( string $charset )
$charset string character set name.

setFrom() public method

Sets the message sender.
public setFrom ( string | array $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]`.

setHtmlBody() public method

Sets message HTML content.
public setHtmlBody ( string $html )
$html string message HTML content.

setReplyTo() public method

Sets the reply-to address of this message.
public setReplyTo ( string | array $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]`.

setSubject() public method

Sets the message subject.
public setSubject ( string $subject )
$subject string message subject

setTextBody() public method

Sets message plain text content.
public setTextBody ( string $text )
$text string message plain text content.

setTo() public method

Sets the message recipient(s).
public setTo ( string | array $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]`.

toString() public method

Returns string representation of this message.
public toString ( ) : string
return string the string representation of this message.