Abstract Class yii\mail\BaseMessage

Inheritanceyii\mail\BaseMessage » yii\base\BaseObject
Implementsyii\base\Configurable, yii\mail\MessageInterface
Subclassesyii\swiftmailer\Message
Available since version2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/mail/BaseMessage.php

BaseMessage serves as a base class that implements the send() method required by yii\mail\MessageInterface.

By default, send() will use the "mailer" application component to send the current message. The "mailer" application component should be a mailer instance implementing yii\mail\MailerInterface.

See also yii\mail\BaseMailer.

Public Properties

Hide inherited properties

Property Type Description Defined By
$bcc string|array The Bcc (hidden copy receiver) addresses of this message. yii\mail\MessageInterface
$cc string|array The Cc (additional copy receiver) addresses of this message. yii\mail\MessageInterface
$charset string The character set of this message. yii\mail\MessageInterface
$from string|array The sender yii\mail\MessageInterface
$htmlBody string Message HTML content. yii\mail\MessageInterface
$mailer yii\mail\MailerInterface|null The mailer instance that created this message. yii\mail\BaseMessage
$replyTo string|array The reply-to address of this message. yii\mail\MessageInterface
$subject string The message subject yii\mail\MessageInterface
$textBody string Message plain text content. yii\mail\MessageInterface
$to string|array The message recipients yii\mail\MessageInterface

Public Methods

Hide inherited methods

Method Description Defined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__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
attach() Attaches existing file to the email message. yii\mail\MessageInterface
attachContent() Attach specified content as file for the email message. yii\mail\MessageInterface
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\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
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\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

Property Details

Hide inherited properties

$mailer public property

The mailer instance that created this message. For independently created messages this is null.

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

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

            
__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

                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

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

                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

                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

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

public string __toString ( )
return string

The string representation of this object.

                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.

                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);
    }
}

            
attach() public abstract method

Defined in: yii\mail\MessageInterface::attach()

Attaches existing file to the email message.

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

                public function attach($fileName, array $options = []);

            
attachContent() public abstract method

Defined in: yii\mail\MessageInterface::attachContent()

Attach specified content as file for the email message.

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

                public function attachContent($content, array $options = []);

            
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

                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

                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.

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

            
embed() public abstract method

Defined in: yii\mail\MessageInterface::embed()

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

                public function embed($fileName, array $options = []);

            
embedContent() public abstract method

Defined in: yii\mail\MessageInterface::embedContent()

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

                public function embedContent($content, array $options = []);

            
getBcc() public abstract method

Defined in: yii\mail\MessageInterface::getBcc()

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

public abstract string|array getBcc ( )
return string|array

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

                public function getBcc();

            
getCc() public abstract method

Defined in: yii\mail\MessageInterface::getCc()

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

public abstract string|array getCc ( )
return string|array

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

                public function getCc();

            
getCharset() public abstract method

Defined in: yii\mail\MessageInterface::getCharset()

Returns the character set of this message.

public abstract string getCharset ( )
return string

The character set of this message.

                public function getCharset();

            
getFrom() public abstract method

Defined in: yii\mail\MessageInterface::getFrom()

Returns the message sender.

public abstract string|array getFrom ( )
return string|array

The sender

                public function getFrom();

            
getReplyTo() public abstract method

Defined in: yii\mail\MessageInterface::getReplyTo()

Returns the reply-to address of this message.

public abstract string|array getReplyTo ( )
return string|array

The reply-to address of this message.

                public function getReplyTo();

            
getSubject() public abstract method

Defined in: yii\mail\MessageInterface::getSubject()

Returns the message subject.

public abstract string getSubject ( )
return string

The message subject

                public function getSubject();

            
getTo() public abstract method

Defined in: yii\mail\MessageInterface::getTo()

Returns the message recipient(s).

public abstract string|array getTo ( )
return string|array

The message recipients

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

                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:

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

                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 ( )

                public function init()
{
}

            
send() public method

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.

                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 abstract method

Defined in: yii\mail\MessageInterface::setBcc()

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

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

                public function setBcc($bcc);

            
setCc() public abstract method

Defined in: yii\mail\MessageInterface::setCc()

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

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

                public function setCc($cc);

            
setCharset() public abstract method

Defined in: yii\mail\MessageInterface::setCharset()

Sets the character set of this message.

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

Character set name.

return $this

Self reference.

                public function setCharset($charset);

            
setFrom() public abstract method

Defined in: yii\mail\MessageInterface::setFrom()

Sets the message sender.

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

                public function setFrom($from);

            
setHtmlBody() public abstract method

Defined in: yii\mail\MessageInterface::setHtmlBody()

Sets message HTML content.

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

Message HTML content.

return $this

Self reference.

                public function setHtmlBody($html);

            
setReplyTo() public abstract method

Defined in: yii\mail\MessageInterface::setReplyTo()

Sets the reply-to address of this message.

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

                public function setReplyTo($replyTo);

            
setSubject() public abstract method

Defined in: yii\mail\MessageInterface::setSubject()

Sets the message subject.

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

Message subject

return $this

Self reference.

                public function setSubject($subject);

            
setTextBody() public abstract method

Defined in: yii\mail\MessageInterface::setTextBody()

Sets message plain text content.

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

Message plain text content.

return $this

Self reference.

                public function setTextBody($text);

            
setTo() public abstract method

Defined in: yii\mail\MessageInterface::setTo()

Sets the message recipient(s).

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

                public function setTo($to);

            
toString() public abstract method

Defined in: yii\mail\MessageInterface::toString()

Returns string representation of this message.

public abstract string toString ( )
return string

The string representation of this message.

                public function toString();