# Class yii\swiftmailer\Message

Inheritance | yii\swiftmailer\Message » yii\mail\BaseMessage » yii\base\BaseObject
Implements | yii\base\Configurable, yii\mail\MessageInterface
Available since version | 2.0
Source Code | https://github.com/yiisoft/yii2-swiftmailer/blob/master/Message.php

Message implements a message class based on SwiftMailer.

See also:

- https://swiftmailer.org/docs/messages.html
- yii\swiftmailer\Mailer

## Public Properties

Hide inherited properties

Property | Type | Description | Defined By
--- | --- | --- | ---
$bcc | string|array | The Bcc (hidden copy receiver) addresses of this message. | yii\swiftmailer\Message
$cc | string|array | The Cc (additional copy receiver) addresses of this message. | yii\swiftmailer\Message
$charset | string | The character set of this message. | yii\swiftmailer\Message
$from | string|array | The sender | yii\swiftmailer\Message
$headers | array | Headers in format: `[name => value]`. | yii\swiftmailer\Message
$htmlBody | string | Message HTML content. | yii\swiftmailer\Message
$mailer | yii\mail\MailerInterface|null | The mailer instance that created this message. | yii\mail\BaseMessage
$priority | integer | Priority value as integer in range: `1..5`, where 1 is the highest priority and 5 is the lowest. | yii\swiftmailer\Message
$readReceiptTo | string | Receipt receive email addresses. | yii\swiftmailer\Message
$replyTo | string|array | The reply-to address of this message. | yii\swiftmailer\Message
$returnPath | string | The bounce email address. | yii\swiftmailer\Message
$signature | array|callable|\Swift_Signer | Signature specification. | yii\swiftmailer\Message
$subject | string | The message subject | yii\swiftmailer\Message
$swiftMessage | \Swift_Message | Swift message instance. | yii\swiftmailer\Message
$textBody | string | Message plain text content. | yii\swiftmailer\Message
$to | string|array | The message recipients | yii\swiftmailer\Message

## Public Methods

Hide inherited methods

Method | Description | Defined By
--- | --- | ---
__call() | Calls the named method which is not a class method. | yii\base\BaseObject
__clone() | This method is called after the object is created by cloning an existing one. | yii\swiftmailer\Message
__construct() | Constructor. | yii\base\BaseObject
__get() | Returns the value of an object property. | yii\base\BaseObject
__isset() | Checks if a property is set, i.e. defined and not null. | yii\base\BaseObject
__set() | Sets value of an object property. | yii\base\BaseObject
__toString() | PHP magic method that returns the string representation of this object. | yii\mail\BaseMessage
__unset() | Sets an object property to null. | yii\base\BaseObject
addHeader() | Adds custom header value to the message. | yii\swiftmailer\Message
addSignature() | Adds message signature. | yii\swiftmailer\Message
attach() | Attaches existing file to the email message. | yii\swiftmailer\Message
attachContent() | Attach specified content as file for the email message. | yii\swiftmailer\Message
canGetProperty() | Returns a value indicating whether a property can be read. | yii\base\BaseObject
canSetProperty() | Returns a value indicating whether a property can be set. | yii\base\BaseObject
className() | Returns the fully qualified name of this class. | yii\base\BaseObject
embed() | Attach a file and return it's CID source. | yii\swiftmailer\Message
embedContent() | Attach a content as file and return it's CID source. | yii\swiftmailer\Message
getBcc() | Returns the Bcc (hidden copy receiver) addresses of this message. | yii\swiftmailer\Message
getCc() | Returns the Cc (additional copy receiver) addresses of this message. | yii\swiftmailer\Message
getCharset() | Returns the character set of this message. | yii\swiftmailer\Message
getFrom() | Returns the message sender. | yii\swiftmailer\Message
getHeader() | Returns all values for the specified header. | yii\swiftmailer\Message
getMailer() | returns mailer instance. | yii\swiftmailer\Message
getPriority() | Returns the priority of this message. | yii\swiftmailer\Message
getReadReceiptTo() | Get the addresses to which a read-receipt will be sent. | yii\swiftmailer\Message
getReplyTo() | Returns the reply-to address of this message. | yii\swiftmailer\Message
getReturnPath() | Returns the return-path (the bounce address) of this message. | yii\swiftmailer\Message
getSubject() | Returns the message subject. | yii\swiftmailer\Message
getSwiftMessage() |  | yii\swiftmailer\Message
getTo() | Returns the message recipient(s). | yii\swiftmailer\Message
hasMethod() | Returns a value indicating whether a method is defined. | yii\base\BaseObject
hasProperty() | Returns a value indicating whether a property is defined. | yii\base\BaseObject
init() | Initializes the object. | yii\base\BaseObject
send() | Sends this email message. | yii\mail\BaseMessage
setBcc() | Sets the Bcc (hidden copy receiver) addresses of this message. | yii\swiftmailer\Message
setCc() | Sets the Cc (additional copy receiver) addresses of this message. | yii\swiftmailer\Message
setCharset() | Sets the character set of this message. | yii\swiftmailer\Message
setFrom() | Sets the message sender. | yii\swiftmailer\Message
setHeader() | Sets custom header value to the message. | yii\swiftmailer\Message
setHeaders() | Sets custom header values to the message. | yii\swiftmailer\Message
setHtmlBody() | Sets message HTML content. | yii\swiftmailer\Message
setPriority() | Set the priority of this message. | yii\swiftmailer\Message
setReadReceiptTo() | Sets the ask for a delivery receipt from the recipient to be sent to $addresses. | yii\swiftmailer\Message
setReplyTo() | Sets the reply-to address of this message. | yii\swiftmailer\Message
setReturnPath() | Set the return-path (the bounce address) of this message. | yii\swiftmailer\Message
setSignature() | Sets message signature | yii\swiftmailer\Message
setSubject() | Sets the message subject. | yii\swiftmailer\Message
setTextBody() | Sets message plain text content. | yii\swiftmailer\Message
setTo() | Sets the message recipient(s). | yii\swiftmailer\Message
toString() | Returns string representation of this message. | yii\swiftmailer\Message

## Protected Methods

Hide inherited methods

Method | Description | Defined By
--- | --- | ---
createSwiftMessage() | Creates the Swift email message instance. | yii\swiftmailer\Message
createSwiftSigner() | Creates signer from it's configuration. | yii\swiftmailer\Message
setBody() | Sets the message body. | yii\swiftmailer\Message

## Property Details

Hide inherited properties

$bcc public property

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

public string|array getBcc ( )
public $this setBcc ( $bcc )
$cc public property

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

public string|array getCc ( )
public $this setCc ( $cc )
$charset public property

The character set of this message.

public string getCharset ( )
public $this setCharset ( $charset )
$from public property

The sender

public string|array getFrom ( )
public $this setFrom ( $from )
$headers public property

Headers in format: `[name => value]`.

public array $headers = null
$htmlBody public write-only property

Message HTML content.

public $this setHtmlBody ( $html )
$priority public property

Priority value as integer in range: `1..5`, where 1 is the highest priority and 5 is the lowest.

public integer $priority = null
$readReceiptTo public property

Receipt receive email addresses. Note that the type of this property differs in getter and setter. See getReadReceiptTo() and setReadReceiptTo() for details.

public string $readReceiptTo = null
$replyTo public property

The reply-to address of this message.

public string|array getReplyTo ( )
public $this setReplyTo ( $replyTo )
$returnPath public property

The bounce email address.

public string $returnPath = null
$signature public property

Signature specification. See addSignature() for details on how it should be specified.

public array|callable|\Swift_Signer $signature = null
$subject public property

The message subject

public string getSubject ( )
public $this setSubject ( $subject )
$swiftMessage public property

Swift message instance.

public \Swift_Message $swiftMessage = null
$textBody public write-only property

Message plain text content.

public $this setTextBody ( $text )
$to public property

The message recipients

public string|array getTo ( )
public $this setTo ( $to )

## Method Details

Hide inherited methods

__call() public method

Defined in: yii\base\BaseObject::__call()

Calls the named method which is not a class method.

Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.

public mixed __call ( $name, $params )
$name | string | The method name
$params | array | Method parameters
return | mixed | The method return value
throws | yii\base\UnknownMethodException | when calling unknown method

Source code

                    public function __call($name, $params)
    {
        throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
    }

__clone() public method (available since version 2.0.7)

This method is called after the object is created by cloning an existing one.

It ensures $swiftMessage and signers is also cloned.

public void __clone ( )

Source code

                    public function __clone()
    {
        if ($this->_swiftMessage !== null) {
            $this->_swiftMessage = clone $this->_swiftMessage;
        }
        foreach ($this->signers as $key => $signer) {
            $this->signers[$key] = clone $signer;
        }
    }

__construct() public method

Defined in: yii\base\BaseObject::__construct()

Constructor.

The default implementation does two things:

- Initializes the object with the given configuration `$config`.
- Call init().

If this method is overridden in a child class, it is recommended that

- the last parameter of the constructor is a configuration array, like `$config` here.
- call the parent implementation at the end of the constructor.

public void __construct ( $config = [] )
$config | array | Name-value pairs that will be used to initialize the object properties

Source code

                    public function __construct($config = [])
    {
        if (!empty($config)) {
            Yii::configure($this, $config);
        }
        $this->init();
    }

__get() public method

Defined in: yii\base\BaseObject::__get()

Returns the value of an object property.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing `$value = $object->property;`.

See also __set().

public mixed __get ( $name )
$name | string | The property name
return | mixed | The property value
throws | yii\base\UnknownPropertyException | if the property is not defined
throws | yii\base\InvalidCallException | if the property is write-only

Source code

                    public function __get($name)
    {
        $getter = 'get' . $name;
        if (method_exists($this, $getter)) {
            return $this->$getter();
        } elseif (method_exists($this, 'set' . $name)) {
            throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
        }
        throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
    }

__isset() public method

Defined in: yii\base\BaseObject::__isset()

Checks if a property is set, i.e. defined and not null.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing `isset($object->property)`.

Note that if the property is not defined, false will be returned.

See also https://www.php.net/manual/en/function.isset.php.

public boolean __isset ( $name )
$name | string | The property name or the event name
return | boolean | Whether the named property is set (not null).

Source code

                    public function __isset($name)
    {
        $getter = 'get' . $name;
        if (method_exists($this, $getter)) {
            return $this->$getter() !== null;
        }
        return false;
    }

__set() public method

Defined in: yii\base\BaseObject::__set()

Sets value of an object property.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing `$object->property = $value;`.

See also __get().

public void __set ( $name, $value )
$name | string | The property name or the event name
$value | mixed | The property value
throws | yii\base\UnknownPropertyException | if the property is not defined
throws | yii\base\InvalidCallException | if the property is read-only

Source code

                    public function __set($name, $value)
    {
        $setter = 'set' . $name;
        if (method_exists($this, $setter)) {
            $this->$setter($value);
        } elseif (method_exists($this, 'get' . $name)) {
            throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
        } else {
            throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
        }
    }

__toString() public method

Defined in: yii\mail\BaseMessage::__toString()

PHP magic method that returns the string representation of this object.

public string __toString ( )
return | string | The string representation of this object.

Source code

                    public function __toString()
    {
        // __toString cannot throw exception
        // use trigger_error to bypass this limitation
        try {
            return $this->toString();
        } catch (\Exception $e) {
            ErrorHandler::convertExceptionToError($e);
            return '';
        }
    }

__unset() public method

Defined in: yii\base\BaseObject::__unset()

Sets an object property to null.

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing `unset($object->property)`.

Note that if the property is not defined, this method will do nothing. If the property is read-only, it will throw an exception.

See also https://www.php.net/manual/en/function.unset.php.

public void __unset ( $name )
$name | string | The property name
throws | yii\base\InvalidCallException | if the property is read only.

Source code

                    public function __unset($name)
    {
        $setter = 'set' . $name;
        if (method_exists($this, $setter)) {
            $this->$setter(null);
        } elseif (method_exists($this, 'get' . $name)) {
            throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '::' . $name);
        }
    }

addHeader() public method (available since version 2.0.6)

Adds custom header value to the message.

Several invocations of this method with the same name will add multiple header values.

public $this addHeader ( $name, $value )
$name | string | Header name.
$value | string | Header value.
return | $this | Self reference.

Source code

                    public function addHeader($name, $value)
    {
        $this->getSwiftMessage()->getHeaders()->addTextHeader($name, $value);
        return $this;
    }

addSignature() public method (available since version 2.0.6)

Adds message signature.

public $this addSignature ( $signature )

$signature

array|callable|\Swift_Signer

Signature specification, this can be:

- \Swift_Signer instance
- callable, which returns \Swift_Signer instance
- configuration array for the signer creation

return | $this | Self reference
throws | yii\base\InvalidConfigException | on invalid signature configuration

Source code

                    public function addSignature($signature)
    {
        if ($signature instanceof \Swift_Signer) {
            $signer = $signature;
        } elseif (is_callable($signature)) {
            $signer = call_user_func($signature);
        } elseif (is_array($signature)) {
            $signer = $this->createSwiftSigner($signature);
        } else {
            throw new InvalidConfigException('Signature should be instance of "Swift_Signer", callable or array configuration');
        }
        $this->getSwiftMessage()->attachSigner($signer);
        $this->signers[] = $signer;
        return $this;
    }

attach() public method

Attaches existing file to the email message.

public $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.

Source code

                    public function attach($fileName, array $options = [])
    {
        $attachment = \Swift_Attachment::fromPath($fileName);
        if (!empty($options['fileName'])) {
            $attachment->setFilename($options['fileName']);
        }
        if (!empty($options['contentType'])) {
            $attachment->setContentType($options['contentType']);
        }
        $this->getSwiftMessage()->attach($attachment);
        return $this;
    }

attachContent() public method

Attach specified content as file for the email message.

public $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.

Source code

                    public function attachContent($content, array $options = [])
    {
        $attachment = new \Swift_Attachment($content);
        if (!empty($options['fileName'])) {
            $attachment->setFilename($options['fileName']);
        }
        if (!empty($options['contentType'])) {
            $attachment->setContentType($options['contentType']);
        }
        if (!empty($options['setDisposition'])) {
          $attachment->setDisposition($options['setDisposition']);
        }
        $this->getSwiftMessage()->attach($attachment);
        return $this;
    }

canGetProperty() public method

Defined in: yii\base\BaseObject::canGetProperty()

Returns a value indicating whether a property can be read.

A property is readable if:

- the class has a getter method associated with the specified name (in this case, property name is case-insensitive);
- the class has a member variable with the specified name (when `$checkVars` is true);

See also canSetProperty().

public boolean canGetProperty ( $name, $checkVars = true )
$name | string | The property name
$checkVars | boolean | Whether to treat member variables as properties
return | boolean | Whether the property can be read

Source code

                    public function canGetProperty($name, $checkVars = true)
    {
        return method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name);
    }

canSetProperty() public method

Defined in: yii\base\BaseObject::canSetProperty()

Returns a value indicating whether a property can be set.

A property is writable if:

- the class has a setter method associated with the specified name (in this case, property name is case-insensitive);
- the class has a member variable with the specified name (when `$checkVars` is true);

See also canGetProperty().

public boolean canSetProperty ( $name, $checkVars = true )
$name | string | The property name
$checkVars | boolean | Whether to treat member variables as properties
return | boolean | Whether the property can be written

Source code

                    public function canSetProperty($name, $checkVars = true)
    {
        return method_exists($this, 'set' . $name) || $checkVars && property_exists($this, $name);
    }

className() public static method
Deprecated since 2.0.14. On PHP >=5.5, use `::class` instead.

Defined in: yii\base\BaseObject::className()

Returns the fully qualified name of this class.

public static string className ( )
return | string | The fully qualified name of this class.

Source code

                    public static function className()
    {
        return get_called_class();
    }

createSwiftMessage() protected method

Creates the Swift email message instance.

protected \Swift_Message createSwiftMessage ( )
return | \Swift_Message | Email message instance.

Source code

                    protected function createSwiftMessage()
    {
        return new \Swift_Message();
    }

createSwiftSigner() protected method (available since version 2.0.6)

Creates signer from it's configuration.

protected \Swift_Signer createSwiftSigner ( $signature )
$signature | array | Signature configuration: `[type: string, key: string|null, file: string|null, domain: string|null, selector: string|null]`
return | \Swift_Signer | Signer instance
throws | yii\base\InvalidConfigException | on invalid configuration provided

Source code

                    protected function createSwiftSigner($signature)
    {
        if (!isset($signature['type'])) {
            throw new InvalidConfigException('Signature configuration should contain "type" key');
        }
        $signature['type'] = strtolower($signature['type']);
        if (!in_array($signature['type'], ['dkim', 'opendkim'], true)) {
            throw new InvalidConfigException("Unrecognized signature type '{$signature['type']}'");
        }
        if (isset($signature['key'])) {
            $privateKey = $signature['key'];
        } elseif (isset($signature['file'])) {
            $privateKey = file_get_contents(Yii::getAlias($signature['file']));
        } else {
            throw new InvalidConfigException("Either 'key' or 'file' signature option should be specified");
        }
        $domain = ArrayHelper::getValue($signature, 'domain');
        $selector = ArrayHelper::getValue($signature, 'selector');
        if ($signature['type'] === 'opendkim') {
            Yii::warning(__METHOD__ . '(): signature type "opendkim" is deprecated, use "dkim" instead.');
            return new \Swift_Signers_OpenDKIMSigner($privateKey, $domain, $selector);
        }
        return new \Swift_Signers_DKIMSigner($privateKey, $domain, $selector);
    }

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.

public 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.

Source code

                    public function embed($fileName, array $options = [])
    {
        $embedFile = \Swift_EmbeddedFile::fromPath($fileName);
        if (!empty($options['fileName'])) {
            $embedFile->setFilename($options['fileName']);
        }
        if (!empty($options['contentType'])) {
            $embedFile->setContentType($options['contentType']);
        }
        return $this->getSwiftMessage()->embed($embedFile);
    }

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.

public 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.

Source code

                    public function embedContent($content, array $options = [])
    {
        $embedFile = new \Swift_EmbeddedFile($content);
        if (!empty($options['fileName'])) {
            $embedFile->setFilename($options['fileName']);
        }
        if (!empty($options['contentType'])) {
            $embedFile->setContentType($options['contentType']);
        }
        return $this->getSwiftMessage()->embed($embedFile);
    }

getBcc() public method

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

public string|array getBcc ( )
return | string|array | The Bcc (hidden copy receiver) addresses of this message.

Source code

                    public function getBcc()
    {
        return $this->getSwiftMessage()->getBcc();
    }

getCc() public method

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

public string|array getCc ( )
return | string|array | The Cc (additional copy receiver) addresses of this message.

Source code

                    public function getCc()
    {
        return $this->getSwiftMessage()->getCc();
    }

getCharset() public method

Returns the character set of this message.

public string getCharset ( )
return | string | The character set of this message.

Source code

                    public function getCharset()
    {
        return $this->getSwiftMessage()->getCharset();
    }

getFrom() public method

Returns the message sender.

public string|array getFrom ( )
return | string|array | The sender

Source code

                    public function getFrom()
    {
        return $this->getSwiftMessage()->getFrom();
    }

getHeader() public method (available since version 2.0.6)

Returns all values for the specified header.

public array getHeader ( $name )
$name | string | Header name.
return | array | Header values list.

Source code

                    public function getHeader($name)
    {
        $headerSet = $this->getSwiftMessage()->getHeaders();
        if (!$headerSet->has($name)) {
            return [];
        }
        $headers = [];
        foreach ($headerSet->getAll($name) as $header) {
            $headers[] = $header->getValue();
        }
        return $headers;
    }

getMailer() public method

returns mailer instance.

public yii\swiftmailer\Mailer getMailer ( )
return | yii\swiftmailer\Mailer |

getPriority() public method (available since version 2.0.6)

Returns the priority of this message.

public integer getPriority ( )
return | integer | Priority value as integer in range: `1..5`, where 1 is the highest priority and 5 is the lowest.

Source code

                    public function getPriority()
    {
        return $this->getSwiftMessage()->getPriority();
    }

getReadReceiptTo() public method (available since version 2.0.6)

Get the addresses to which a read-receipt will be sent.

public string getReadReceiptTo ( )
return | string | Receipt receive email addresses.

Source code

                    public function getReadReceiptTo()
    {
        return $this->getSwiftMessage()->getReadReceiptTo();
    }

getReplyTo() public method

Returns the reply-to address of this message.

public string|array getReplyTo ( )
return | string|array | The reply-to address of this message.

Source code

                    public function getReplyTo()
    {
        return $this->getSwiftMessage()->getReplyTo();
    }

getReturnPath() public method (available since version 2.0.6)

Returns the return-path (the bounce address) of this message.

public string getReturnPath ( )
return | string | The bounce email address.

Source code

                    public function getReturnPath()
    {
        return $this->getSwiftMessage()->getReturnPath();
    }

getSubject() public method

Returns the message subject.

public string getSubject ( )
return | string | The message subject

Source code

                    public function getSubject()
    {
        return $this->getSwiftMessage()->getSubject();
    }

getSwiftMessage() public method

public \Swift_Message getSwiftMessage ( )
return | \Swift_Message | Swift message instance.

Source code

                    public function getSwiftMessage()
    {
        if ($this->_swiftMessage === null) {
            $this->_swiftMessage = $this->createSwiftMessage();
        }
        return $this->_swiftMessage;
    }

getTo() public method

Returns the message recipient(s).

public string|array getTo ( )
return | string|array | The message recipients

Source code

                    public function getTo()
    {
        return $this->getSwiftMessage()->getTo();
    }

hasMethod() public method

Defined in: yii\base\BaseObject::hasMethod()

Returns a value indicating whether a method is defined.

The default implementation is a call to php function `method_exists()`. You may override this method when you implemented the php magic method `__call()`.

public boolean hasMethod ( $name )
$name | string | The method name
return | boolean | Whether the method is defined

Source code

                    public function hasMethod($name)
    {
        return method_exists($this, $name);
    }

hasProperty() public method

Defined in: yii\base\BaseObject::hasProperty()

Returns a value indicating whether a property is defined.

A property is defined if:

- the class has a getter or setter method associated with the specified name (in this case, property name is case-insensitive);
- the class has a member variable with the specified name (when `$checkVars` is true);

See also:

- canGetProperty()
- canSetProperty()

public boolean hasProperty ( $name, $checkVars = true )
$name | string | The property name
$checkVars | boolean | Whether to treat member variables as properties
return | boolean | Whether the property is defined

Source code

                    public function hasProperty($name, $checkVars = true)
    {
        return $this->canGetProperty($name, $checkVars) || $this->canSetProperty($name, false);
    }

init() public method

Defined in: yii\base\BaseObject::init()

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

public void init ( )

Source code

                    public function init()
    {
    }

send() public method

Defined in: yii\mail\BaseMessage::send()

Sends this email message.

public boolean send ( yii\mail\MailerInterface $mailer = null )
$mailer | yii\mail\MailerInterface|null | The mailer that should be used to send this message. If no mailer is given it will first check if $mailer is set and if not, the "mailer" application component will be used instead.
return | boolean | Whether this message is sent successfully.

Source code

                    public function send(MailerInterface $mailer = null)
    {
        if ($mailer === null && $this->mailer === null) {
            $mailer = Yii::$app->getMailer();
        } elseif ($mailer === null) {
            $mailer = $this->mailer;
        }
        return $mailer->send($this);
    }

setBcc() public method

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

public $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.

Source code

                    public function setBcc($bcc)
    {
        $this->getSwiftMessage()->setBcc($bcc);
        return $this;
    }

setBody() protected method

Sets the message body.

If body is already set and its content type matches given one, it will be overridden, if content type miss match the multipart message will be composed.

protected void setBody ( $body, $contentType )
$body | string | Body content.
$contentType | string | Body content type.

Source code

                    protected function setBody($body, $contentType)
    {
        $message = $this->getSwiftMessage();
        $oldBody = $message->getBody();
        $charset = $message->getCharset();
        if (empty($oldBody)) {
            $parts = $message->getChildren();
            $partFound = false;
            foreach ($parts as $key => $part) {
                if (!($part instanceof \Swift_Mime_Attachment)) {
                    /* @var $part \Swift_Mime_MimePart */
                    if ($part->getContentType() == $contentType) {
                        $charset = $part->getCharset();
                        unset($parts[$key]);
                        $partFound = true;
                        break;
                    }
                }
            }
            if ($partFound) {
                reset($parts);
                $message->setChildren($parts);
                $message->addPart($body, $contentType, $charset);
            } else {
                $message->setBody($body, $contentType);
            }
        } else {
            $oldContentType = $message->getContentType();
            if ($oldContentType == $contentType) {
                $message->setBody($body, $contentType);
            } else {
                $message->setBody(null);
                $message->setContentType(null);
                $message->addPart($oldBody, $oldContentType, $charset);
                $message->addPart($body, $contentType, $charset);
            }
        }
    }

setCc() public method

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

public $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.

Source code

                    public function setCc($cc)
    {
        $this->getSwiftMessage()->setCc($cc);
        return $this;
    }

setCharset() public method

Sets the character set of this message.

public $this setCharset ( $charset )
$charset | string | Character set name.
return | $this | Self reference.

Source code

                    public function setCharset($charset)
    {
        $this->getSwiftMessage()->setCharset($charset);
        return $this;
    }

setFrom() public method

Sets the message sender.

public $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.

Source code

                    public function setFrom($from)
    {
        $this->getSwiftMessage()->setFrom($from);
        return $this;
    }

setHeader() public method (available since version 2.0.6)

Sets custom header value to the message.

public $this setHeader ( $name, $value )
$name | string | Header name.
$value | string|array | Header value or values.
return | $this | Self reference.

Source code

                    public function setHeader($name, $value)
    {
        $headerSet = $this->getSwiftMessage()->getHeaders();
        if ($headerSet->has($name)) {
            $headerSet->remove($name);
        }
        foreach ((array)$value as $v) {
            $headerSet->addTextHeader($name, $v);
        }
        return $this;
    }

setHeaders() public method (available since version 2.0.7)

Sets custom header values to the message.

public $this setHeaders ( $headers )
$headers | array | Headers in format: `[name => value]`.
return | $this | Self reference.

Source code

                    public function setHeaders($headers)
    {
        foreach ($headers as $name => $value) {
            $this->setHeader($name, $value);
        }
        return $this;
    }

setHtmlBody() public method

Sets message HTML content.

public $this setHtmlBody ( $html )
$html | string | Message HTML content.
return | $this | Self reference.

Source code

                    public function setHtmlBody($html)
    {
        $this->setBody($html, 'text/html');
        return $this;
    }

setPriority() public method (available since version 2.0.6)

Set the priority of this message.

public $this setPriority ( $priority )
$priority | integer | Priority value, should be an integer in range: `1..5`, where 1 is the highest priority and 5 is the lowest.
return | $this | Self reference.

Source code

                    public function setPriority($priority)
    {
        $this->getSwiftMessage()->setPriority($priority);
        return $this;
    }

setReadReceiptTo() public method (available since version 2.0.6)

Sets the ask for a delivery receipt from the recipient to be sent to $addresses.

public $this setReadReceiptTo ( $addresses )
$addresses | string|array | Receipt receive email address(es).
return | $this | Self reference.

Source code

                    public function setReadReceiptTo($addresses)
    {
        $this->getSwiftMessage()->setReadReceiptTo($addresses);
        return $this;
    }

setReplyTo() public method

Sets the reply-to address of this message.

public $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.

Source code

                    public function setReplyTo($replyTo)
    {
        $this->getSwiftMessage()->setReplyTo($replyTo);
        return $this;
    }

setReturnPath() public method (available since version 2.0.6)

Set the return-path (the bounce address) of this message.

public $this setReturnPath ( $address )
$address | string | The bounce email address.
return | $this | Self reference.

Source code

                    public function setReturnPath($address)
    {
        $this->getSwiftMessage()->setReturnPath($address);
        return $this;
    }

setSignature() public method (available since version 2.0.6)

Sets message signature

public $this setSignature ( $signature )
$signature | array|callable|\Swift_Signer | Signature specification. See addSignature() for details on how it should be specified.
return | $this | Self reference.

Source code

                    public function setSignature($signature)
    {
        if (!empty($this->signers)) {
            // clear previously set signers
            $swiftMessage = $this->getSwiftMessage();
            foreach ($this->signers as $signer) {
                $swiftMessage->detachSigner($signer);
            }
            $this->signers = [];
        }
        return $this->addSignature($signature);
    }

setSubject() public method

Sets the message subject.

public $this setSubject ( $subject )
$subject | string | Message subject
return | $this | Self reference.

Source code

                    public function setSubject($subject)
    {
        $this->getSwiftMessage()->setSubject($subject);
        return $this;
    }

setTextBody() public method

Sets message plain text content.

public $this setTextBody ( $text )
$text | string | Message plain text content.
return | $this | Self reference.

Source code

                    public function setTextBody($text)
    {
        $this->setBody($text, 'text/plain');
        return $this;
    }

setTo() public method

Sets the message recipient(s).

public $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.

Source code

                    public function setTo($to)
    {
        $this->getSwiftMessage()->setTo($to);
        return $this;
    }

toString() public method

Returns string representation of this message.

public string toString ( )
return | string | The string representation of this message.

Source code

                    public function toString()
    {
        return $this->getSwiftMessage()->toString();
    }