0 追蹤者

抽象類別 yii\mail\BaseMessage

繼承關係yii\mail\BaseMessage » yii\base\BaseObject
實作介面yii\base\Configurable, yii\mail\MessageInterface
自版本起可用2.0
原始碼 https://github.com/yiisoft/yii2/blob/master/framework/mail/BaseMessage.php

BaseMessage 作為基底類別,實作了 send() 方法,此方法為 yii\mail\MessageInterface 所需。

預設情況下,send() 將使用 "mailer" 應用程式元件來發送當前訊息。"mailer" 應用程式元件應為郵件器實例,其需實作 yii\mail\MailerInterface

另請參閱 yii\mail\BaseMailer

公開屬性

隱藏繼承的屬性

屬性 類型 描述 定義於
$bcc string|array 此訊息的密件副本 (隱藏副本接收者) 地址。 yii\mail\MessageInterface
$cc string|array 此訊息的副本 (額外副本接收者) 地址。 yii\mail\MessageInterface
$charset string 此訊息的字元集。 yii\mail\MessageInterface
$from string|array 寄件者 yii\mail\MessageInterface
$htmlBody string 訊息 HTML 內容。 yii\mail\MessageInterface
$mailer yii\mail\MailerInterface|null 建立此訊息的郵件器實例。 yii\mail\BaseMessage
$replyTo string|array 此訊息的回覆地址。 yii\mail\MessageInterface
$subject string 訊息主旨 yii\mail\MessageInterface
$textBody string 訊息純文字內容。 yii\mail\MessageInterface
$to string|array 訊息收件者 yii\mail\MessageInterface

公開方法

隱藏繼承的方法

方法 描述 定義於
__call() 呼叫未作為類別方法的具名方法。 yii\base\BaseObject
__construct() 建構子。 yii\base\BaseObject
__get() 傳回物件屬性的值。 yii\base\BaseObject
__isset() 檢查屬性是否已設定,即已定義且非 null。 yii\base\BaseObject
__set() 設定物件屬性的值。 yii\base\BaseObject
__toString() PHP 魔術方法,傳回此物件的字串表示形式。 yii\mail\BaseMessage
__unset() 將物件屬性設定為 null。 yii\base\BaseObject
attach() 將現有檔案附加到電子郵件訊息。 yii\mail\MessageInterface
attachContent() 將指定的內容作為檔案附加到電子郵件訊息。 yii\mail\MessageInterface
canGetProperty() 傳回一個值,指示是否可以讀取屬性。 yii\base\BaseObject
canSetProperty() 傳回一個值,指示是否可以設定屬性。 yii\base\BaseObject
className() 傳回此類別的完整限定名稱。 yii\base\BaseObject
embed() 附加檔案並傳回其 CID 來源。 yii\mail\MessageInterface
embedContent() 將內容作為檔案附加並傳回其 CID 來源。 yii\mail\MessageInterface
getBcc() 傳回此訊息的密件副本 (隱藏副本接收者) 地址。 yii\mail\MessageInterface
getCc() 傳回此訊息的副本 (額外副本接收者) 地址。 yii\mail\MessageInterface
getCharset() 傳回此訊息的字元集。 yii\mail\MessageInterface
getFrom() 傳回訊息寄件者。 yii\mail\MessageInterface
getReplyTo() 傳回此訊息的回覆地址。 yii\mail\MessageInterface
getSubject() 傳回訊息主旨。 yii\mail\MessageInterface
getTo() 傳回訊息收件者。 yii\mail\MessageInterface
hasMethod() 傳回一個值,指示是否已定義方法。 yii\base\BaseObject
hasProperty() 傳回一個值,指示是否已定義屬性。 yii\base\BaseObject
init() 初始化物件。 yii\base\BaseObject
send() 發送此電子郵件訊息。 yii\mail\BaseMessage
setBcc() 設定此訊息的密件副本 (隱藏副本接收者) 地址。 yii\mail\MessageInterface
setCc() 設定此訊息的副本 (額外副本接收者) 地址。 yii\mail\MessageInterface
setCharset() 設定此訊息的字元集。 yii\mail\MessageInterface
setFrom() 設定訊息寄件者。 yii\mail\MessageInterface
setHtmlBody() 設定訊息 HTML 內容。 yii\mail\MessageInterface
setReplyTo() 設定此訊息的回覆地址。 yii\mail\MessageInterface
setSubject() 設定訊息主旨。 yii\mail\MessageInterface
setTextBody() 設定訊息純文字內容。 yii\mail\MessageInterface
setTo() 設定訊息收件者。 yii\mail\MessageInterface
toString() 傳回此訊息的字串表示形式。 yii\mail\MessageInterface

屬性詳情

隱藏繼承的屬性

$mailer 公開屬性

建立此訊息的郵件器實例。對於獨立建立的訊息,此值為 null

方法詳情

隱藏繼承的方法

__call() 公開方法

定義於: yii\base\BaseObject::__call()

呼叫未作為類別方法的具名方法。

請勿直接呼叫此方法,因為它是 PHP 魔術方法,當調用未知方法時將會隱式呼叫。

public mixed __call ( $name, $params )
$name string

方法名稱

$params 陣列

方法參數

回傳 混合型別

方法回傳值

拋出 yii\base\UnknownMethodException

當呼叫未知方法時

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

            
__construct() public method

定義於: yii\base\BaseObject::__construct()

建構子。

預設實作會做兩件事

  • 使用給定的組態 $config 初始化物件。
  • 呼叫 init()

如果子類別覆寫了此方法,建議

  • 建構子的最後一個參數是組態陣列,如同此處的 $config
  • 在建構子的結尾呼叫父類別的實作。
public void __construct ( $config = [] )
$config 陣列

將用於初始化物件屬性的名稱-值配對

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

            
__get() public method

定義於: yii\base\BaseObject::__get()

傳回物件屬性的值。

請勿直接呼叫此方法,因為它是 PHP 魔術方法,當執行 $value = $object->property; 時會被隱式呼叫。

另請參閱 __set()

public mixed __get ( $name )
$name string

屬性名稱

回傳 混合型別

屬性值

拋出 yii\base\UnknownPropertyException

如果屬性未定義

拋出 yii\base\InvalidCallException

如果屬性為唯寫

                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

定義於: yii\base\BaseObject::__isset()

檢查屬性是否已設定,即已定義且非 null。

請勿直接呼叫此方法,因為它是 PHP 魔術方法,當執行 isset($object->property) 時會被隱式呼叫。

請注意,如果屬性未定義,將會回傳 false。

另請參閱 https://php.dev.org.tw/manual/en/function.isset.php

public boolean __isset ( $name )
$name string

屬性名稱或事件名稱

回傳 boolean

具名屬性是否已設定(非 null)。

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

            
__set() public method

定義於: yii\base\BaseObject::__set()

設定物件屬性的值。

請勿直接呼叫此方法,因為它是 PHP 魔術方法,當執行 $object->property = $value; 時會被隱式呼叫。

另請參閱 __get()

public void __set ( $name, $value )
$name string

屬性名稱或事件名稱

$value 混合型別

屬性值

拋出 yii\base\UnknownPropertyException

如果屬性未定義

拋出 yii\base\InvalidCallException

如果屬性為唯讀

                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 魔術方法,傳回此物件的字串表示形式。

public string __toString ( )
回傳 string

此物件的字串表示形式。

                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

定義於: yii\base\BaseObject::__unset()

將物件屬性設定為 null。

請勿直接呼叫此方法,因為它是 PHP 魔術方法,當執行 unset($object->property) 時會被隱式呼叫。

請注意,如果屬性未定義,此方法將不會執行任何操作。如果屬性為唯讀,則會拋出例外。

另請參閱 https://php.dev.org.tw/manual/en/function.unset.php

public void __unset ( $name )
$name string

屬性名稱

拋出 yii\base\InvalidCallException

如果屬性為唯讀。

                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

定義於: yii\mail\MessageInterface::attach()

將現有檔案附加到電子郵件訊息。

public abstract $this attach ( $fileName, array $options = [] )
$fileName string

完整檔案名稱

$options 陣列

嵌入檔案的選項。有效選項為

  • fileName:用於附加檔案的名稱。
  • contentType:附加檔案的 MIME 類型。
回傳 $this

自身參考。

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

            
attachContent() public abstract method

定義於: yii\mail\MessageInterface::attachContent()

將指定的內容作為檔案附加到電子郵件訊息。

public abstract $this attachContent ( $content, array $options = [] )
$content string

附件檔案內容。

$options 陣列

嵌入檔案的選項。有效選項為

  • fileName:用於附加檔案的名稱。
  • contentType:附加檔案的 MIME 類型。
回傳 $this

自身參考。

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

            
canGetProperty() public method

定義於: yii\base\BaseObject::canGetProperty()

傳回一個值,指示是否可以讀取屬性。

如果屬性可讀,條件為

  • 類別具有與指定名稱關聯的 getter 方法(在此情況下,屬性名稱不區分大小寫);
  • 類別具有帶有指定名稱的成員變數(當 $checkVars 為 true 時);

另請參閱 canSetProperty()

public boolean canGetProperty ( $name, $checkVars true )
$name string

屬性名稱

$checkVars boolean

是否將成員變數視為屬性

回傳 boolean

屬性是否可讀

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

            
canSetProperty() public method

定義於: yii\base\BaseObject::canSetProperty()

傳回一個值,指示是否可以設定屬性。

如果屬性可寫入,條件為

  • 類別具有與指定名稱關聯的 setter 方法(在此情況下,屬性名稱不區分大小寫);
  • 類別具有帶有指定名稱的成員變數(當 $checkVars 為 true 時);

另請參閱 canGetProperty()

public boolean canSetProperty ( $name, $checkVars true )
$name string

屬性名稱

$checkVars boolean

是否將成員變數視為屬性

回傳 boolean

屬性是否可寫入

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

            
className() public static method
自 2.0.14 版本起已過時。在 PHP >=5.5 版本上,請改用 ::class

定義於: yii\base\BaseObject::className()

傳回此類別的完整限定名稱。

public static string className ( )
回傳 string

此類別的完整名稱。

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

            
embed() public abstract method

定義於: yii\mail\MessageInterface::embed()

附加檔案並傳回其 CID 來源。

當在訊息中嵌入圖片或其他資料時,應使用此方法。

public abstract string embed ( $fileName, array $options = [] )
$fileName string

檔案名稱。

$options 陣列

嵌入檔案的選項。有效選項為

  • fileName:用於附加檔案的名稱。
  • contentType:附加檔案的 MIME 類型。
回傳 string

附件 CID。

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

            
embedContent() public abstract method

定義於: yii\mail\MessageInterface::embedContent()

將內容作為檔案附加並傳回其 CID 來源。

當在訊息中嵌入圖片或其他資料時,應使用此方法。

public abstract string embedContent ( $content, array $options = [] )
$content string

附件檔案內容。

$options 陣列

嵌入檔案的選項。有效選項為

  • fileName:用於附加檔案的名稱。
  • contentType:附加檔案的 MIME 類型。
回傳 string

附件 CID。

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

            
getBcc() public abstract method

定義於: yii\mail\MessageInterface::getBcc()

傳回此訊息的密件副本 (隱藏副本接收者) 地址。

public abstract string|array getBcc ( )
回傳 string|array

此訊息的密件副本 (隱藏副本接收者) 地址。

                public function getBcc();

            
getCc() public abstract method

定義於: yii\mail\MessageInterface::getCc()

傳回此訊息的副本 (額外副本接收者) 地址。

public abstract string|array getCc ( )
回傳 string|array

此訊息的副本 (額外副本接收者) 地址。

                public function getCc();

            
getCharset() public abstract method

定義於: yii\mail\MessageInterface::getCharset()

傳回此訊息的字元集。

public abstract string getCharset ( )
回傳 string

此訊息的字元集。

                public function getCharset();

            
getFrom() public abstract method

定義於: yii\mail\MessageInterface::getFrom()

傳回訊息寄件者。

public abstract string|array getFrom ( )
回傳 string|array

寄件者

                public function getFrom();

            
getReplyTo() public abstract method

定義於: yii\mail\MessageInterface::getReplyTo()

傳回此訊息的回覆地址。

public abstract string|array getReplyTo ( )
回傳 string|array

此訊息的回覆地址。

                public function getReplyTo();

            
getSubject() public abstract method

定義於: yii\mail\MessageInterface::getSubject()

傳回訊息主旨。

public abstract string getSubject ( )
回傳 string

訊息主旨

                public function getSubject();

            
getTo() public abstract method

定義於: yii\mail\MessageInterface::getTo()

傳回訊息收件者。

public abstract string|array getTo ( )
回傳 string|array

訊息收件者

                public function getTo();

            
hasMethod() public method

定義於: yii\base\BaseObject::hasMethod()

傳回一個值,指示是否已定義方法。

預設實作是對 php 函數 method_exists() 的呼叫。當您實作了 php 魔術方法 __call() 時,您可以覆寫此方法。

public boolean hasMethod ( $name )
$name string

方法名稱

回傳 boolean

方法是否已定義

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

            
hasProperty() public method

定義於: yii\base\BaseObject::hasProperty()

傳回一個值,指示是否已定義屬性。

如果屬性已定義,條件為

  • 類別具有與指定名稱關聯的 getter 或 setter 方法(在此情況下,屬性名稱不區分大小寫);
  • 類別具有帶有指定名稱的成員變數(當 $checkVars 為 true 時);

另請參閱

public boolean hasProperty ( $name, $checkVars true )
$name string

屬性名稱

$checkVars boolean

是否將成員變數視為屬性

回傳 boolean

屬性是否已定義

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

            
init() public method

定義於: yii\base\BaseObject::init()

初始化物件。

在物件使用給定的組態初始化後,此方法會在建構子的結尾被調用。

public void init ( )

                public function init()
{
}

            
send() public method

發送此電子郵件訊息。

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

應該用於發送此訊息的郵件器。如果未給定郵件器,它將首先檢查是否設定了 $mailer,如果沒有,則會改為使用 "mailer" 應用程式元件。

回傳 boolean

此訊息是否成功發送。

                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

定義於: yii\mail\MessageInterface::setBcc()

設定此訊息的密件副本 (隱藏副本接收者) 地址。

public abstract $this setBcc ( $bcc )
$bcc string|array

密件副本接收者電子郵件地址。如果多個收件者應收到此訊息,您可以傳遞地址陣列。您也可以使用格式:[email => name] 除了電子郵件地址外,還指定收件者名稱。

回傳 $this

自身參考。

                public function setBcc($bcc);

            
setCc() public abstract method

定義於: yii\mail\MessageInterface::setCc()

設定此訊息的副本 (額外副本接收者) 地址。

public abstract $this setCc ( $cc )
$cc string|array

副本接收者電子郵件地址。如果多個收件者應收到此訊息,您可以傳遞地址陣列。您也可以使用格式:[email => name] 除了電子郵件地址外,還指定收件者名稱。

回傳 $this

自身參考。

                public function setCc($cc);

            
setCharset() public abstract method

定義於: yii\mail\MessageInterface::setCharset()

設定此訊息的字元集。

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

字元集名稱。

回傳 $this

自身參考。

                public function setCharset($charset);

            
setFrom() public abstract method

定義於: yii\mail\MessageInterface::setFrom()

設定訊息寄件者。

public abstract $this setFrom ( $from )
$from string|array

寄件者電子郵件地址。如果此訊息來自多人,您可以傳遞地址陣列。您也可以使用格式:[email => name] 除了電子郵件地址外,還指定寄件者名稱。

回傳 $this

自身參考。

                public function setFrom($from);

            
setHtmlBody() public abstract method

定義於: yii\mail\MessageInterface::setHtmlBody()

設定訊息 HTML 內容。

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

訊息 HTML 內容。

回傳 $this

自身參考。

                public function setHtmlBody($html);

            
setReplyTo() public abstract method

定義於: yii\mail\MessageInterface::setReplyTo()

設定此訊息的回覆地址。

public abstract $this setReplyTo ( $replyTo )
$replyTo string|array

回覆地址。如果此訊息應回覆給多人,您可以傳遞地址陣列。您也可以使用格式:[email => name] 除了電子郵件地址外,還指定回覆名稱。

回傳 $this

自身參考。

                public function setReplyTo($replyTo);

            
setSubject() public abstract method

定義於: yii\mail\MessageInterface::setSubject()

設定訊息主旨。

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

訊息主旨

回傳 $this

自身參考。

                public function setSubject($subject);

            
setTextBody() public abstract method

定義於: yii\mail\MessageInterface::setTextBody()

設定訊息純文字內容。

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

訊息純文字內容。

回傳 $this

自身參考。

                public function setTextBody($text);

            
setTo() public abstract method

定義於: yii\mail\MessageInterface::setTo()

設定訊息收件者。

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

接收者電子郵件地址。如果多個收件者應收到此訊息,您可以傳遞地址陣列。您也可以使用格式:[email => name] 除了電子郵件地址外,還指定收件者名稱。

回傳 $this

自身參考。

                public function setTo($to);

            
toString() public abstract method

定義於: yii\mail\MessageInterface::toString()

傳回此訊息的字串表示形式。

public abstract string toString ( )
回傳 string

此訊息的字串表示形式。

                public function toString();