抽象類別 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 |
公開方法
屬性詳情
方法詳情
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()");
}
定義於: 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();
}
定義於: 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);
}
定義於: yii\base\BaseObject::__isset()
檢查屬性是否已設定,即已定義且非 null。
請勿直接呼叫此方法,因為它是 PHP 魔術方法,當執行 isset($object->property)
時會被隱式呼叫。
請注意,如果屬性未定義,將會回傳 false。
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;
}
定義於: 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);
}
}
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 '';
}
}
定義於: yii\base\BaseObject::__unset()
將物件屬性設定為 null。
請勿直接呼叫此方法,因為它是 PHP 魔術方法,當執行 unset($object->property)
時會被隱式呼叫。
請注意,如果屬性未定義,此方法將不會執行任何操作。如果屬性為唯讀,則會拋出例外。
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);
}
}
定義於: yii\mail\MessageInterface::attach()
將現有檔案附加到電子郵件訊息。
public abstract $this attach ( $fileName, array $options = [] ) | ||
$fileName | string |
完整檔案名稱 |
$options | 陣列 |
嵌入檔案的選項。有效選項為
|
回傳 | $this |
自身參考。 |
---|
public function attach($fileName, array $options = []);
定義於: yii\mail\MessageInterface::attachContent()
將指定的內容作為檔案附加到電子郵件訊息。
public abstract $this attachContent ( $content, array $options = [] ) | ||
$content | string |
附件檔案內容。 |
$options | 陣列 |
嵌入檔案的選項。有效選項為
|
回傳 | $this |
自身參考。 |
---|
public function attachContent($content, array $options = []);
定義於: 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);
}
定義於: 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);
}
::class
。
定義於: yii\base\BaseObject::className()
傳回此類別的完整限定名稱。
public static string className ( ) | ||
回傳 | string |
此類別的完整名稱。 |
---|
public static function className()
{
return get_called_class();
}
public abstract string embed ( $fileName, array $options = [] ) | ||
$fileName | string |
檔案名稱。 |
$options | 陣列 |
嵌入檔案的選項。有效選項為
|
回傳 | string |
附件 CID。 |
---|
public function embed($fileName, array $options = []);
public abstract string embedContent ( $content, array $options = [] ) | ||
$content | string |
附件檔案內容。 |
$options | 陣列 |
嵌入檔案的選項。有效選項為
|
回傳 | string |
附件 CID。 |
---|
public function embedContent($content, array $options = []);
定義於: yii\mail\MessageInterface::getBcc()
傳回此訊息的密件副本 (隱藏副本接收者) 地址。
public abstract string|array getBcc ( ) | ||
回傳 | string|array |
此訊息的密件副本 (隱藏副本接收者) 地址。 |
---|
public function getBcc();
定義於: yii\mail\MessageInterface::getCc()
傳回此訊息的副本 (額外副本接收者) 地址。
public abstract string|array getCc ( ) | ||
回傳 | string|array |
此訊息的副本 (額外副本接收者) 地址。 |
---|
public function getCc();
定義於: yii\mail\MessageInterface::getCharset()
傳回此訊息的字元集。
public abstract string getCharset ( ) | ||
回傳 | string |
此訊息的字元集。 |
---|
public function getCharset();
定義於: yii\mail\MessageInterface::getFrom()
傳回訊息寄件者。
public abstract string|array getFrom ( ) | ||
回傳 | string|array |
寄件者 |
---|
public function getFrom();
定義於: yii\mail\MessageInterface::getReplyTo()
傳回此訊息的回覆地址。
public abstract string|array getReplyTo ( ) | ||
回傳 | string|array |
此訊息的回覆地址。 |
---|
public function getReplyTo();
定義於: yii\mail\MessageInterface::getSubject()
傳回訊息主旨。
public abstract string getSubject ( ) | ||
回傳 | string |
訊息主旨 |
---|
public function getSubject();
定義於: yii\mail\MessageInterface::getTo()
傳回訊息收件者。
public abstract string|array getTo ( ) | ||
回傳 | string|array |
訊息收件者 |
---|
public function getTo();
定義於: 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);
}
定義於: 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);
}
public void init ( ) |
public function init()
{
}
發送此電子郵件訊息。
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);
}
定義於: yii\mail\MessageInterface::setBcc()
設定此訊息的密件副本 (隱藏副本接收者) 地址。
public abstract $this setBcc ( $bcc ) | ||
$bcc | string|array |
密件副本接收者電子郵件地址。如果多個收件者應收到此訊息,您可以傳遞地址陣列。您也可以使用格式: |
回傳 | $this |
自身參考。 |
---|
public function setBcc($bcc);
定義於: yii\mail\MessageInterface::setCc()
設定此訊息的副本 (額外副本接收者) 地址。
public abstract $this setCc ( $cc ) | ||
$cc | string|array |
副本接收者電子郵件地址。如果多個收件者應收到此訊息,您可以傳遞地址陣列。您也可以使用格式: |
回傳 | $this |
自身參考。 |
---|
public function setCc($cc);
定義於: yii\mail\MessageInterface::setCharset()
設定此訊息的字元集。
public abstract $this setCharset ( $charset ) | ||
$charset | string |
字元集名稱。 |
回傳 | $this |
自身參考。 |
---|
public function setCharset($charset);
定義於: yii\mail\MessageInterface::setFrom()
設定訊息寄件者。
public abstract $this setFrom ( $from ) | ||
$from | string|array |
寄件者電子郵件地址。如果此訊息來自多人,您可以傳遞地址陣列。您也可以使用格式: |
回傳 | $this |
自身參考。 |
---|
public function setFrom($from);
定義於: yii\mail\MessageInterface::setHtmlBody()
設定訊息 HTML 內容。
public abstract $this setHtmlBody ( $html ) | ||
$html | string |
訊息 HTML 內容。 |
回傳 | $this |
自身參考。 |
---|
public function setHtmlBody($html);
定義於: yii\mail\MessageInterface::setReplyTo()
設定此訊息的回覆地址。
public abstract $this setReplyTo ( $replyTo ) | ||
$replyTo | string|array |
回覆地址。如果此訊息應回覆給多人,您可以傳遞地址陣列。您也可以使用格式: |
回傳 | $this |
自身參考。 |
---|
public function setReplyTo($replyTo);
定義於: yii\mail\MessageInterface::setSubject()
設定訊息主旨。
public abstract $this setSubject ( $subject ) | ||
$subject | string |
訊息主旨 |
回傳 | $this |
自身參考。 |
---|
public function setSubject($subject);
定義於: yii\mail\MessageInterface::setTextBody()
設定訊息純文字內容。
public abstract $this setTextBody ( $text ) | ||
$text | string |
訊息純文字內容。 |
回傳 | $this |
自身參考。 |
---|
public function setTextBody($text);
定義於: yii\mail\MessageInterface::setTo()
設定訊息收件者。
public abstract $this setTo ( $to ) | ||
$to | string|array |
接收者電子郵件地址。如果多個收件者應收到此訊息,您可以傳遞地址陣列。您也可以使用格式: |
回傳 | $this |
自身參考。 |
---|
public function setTo($to);
定義於: yii\mail\MessageInterface::toString()
傳回此訊息的字串表示形式。
public abstract string toString ( ) | ||
回傳 | string |
此訊息的字串表示形式。 |
---|
public function toString();
為了發表評論,請註冊 或 登入。