抽象类 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 | array |
方法参数 |
| return | mixed |
方法返回值 |
|---|---|---|
| throws | 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 | array |
用于初始化对象属性的名称-值对 |
public function __construct($config = [])
{
if (!empty($config)) {
Yii::configure($this, $config);
}
$this->init();
}
Defined in: yii\base\BaseObject::__get()
返回对象属性的值。
不要直接调用此方法,因为它是 PHP 的魔法方法,会在执行 $value = $object->property; 时隐式调用。
另见 __set().
| public mixed __get ( $name ) | ||
| $name | string |
属性名称 |
| return | mixed |
属性值 |
|---|---|---|
| throws | yii\base\UnknownPropertyException |
如果属性未定义 |
| throws | 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);
}
Defined in: yii\base\BaseObject::__isset()
检查属性是否已设置,即定义且不为 null。
不要直接调用此方法,因为它是 PHP 的魔法方法,会在执行 isset($object->property) 时隐式调用。
注意,如果属性未定义,则将返回 false。
| public boolean __isset ( $name ) | ||
| $name | string |
属性名称或事件名称 |
| return | boolean |
命名的属性是否设置(不为 null)。 |
|---|---|---|
public function __isset($name)
{
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
return $this->$getter() !== null;
}
return false;
}
Defined in: yii\base\BaseObject::__set()
设置对象属性的值。
不要直接调用此方法,因为它是 PHP 的魔法方法,会在执行 $object->property = $value; 时隐式调用。
另见 __get().
| public void __set ( $name, $value ) | ||
| $name | string |
属性名称或事件名称 |
| $value | mixed |
属性值 |
| throws | yii\base\UnknownPropertyException |
如果属性未定义 |
|---|---|---|
| throws | 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 ( ) | ||
| return | 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 '';
}
}
Defined in: yii\base\BaseObject::__unset()
将对象属性设置为 null。
不要直接调用此方法,因为它是 PHP 的魔法方法,会在执行 unset($object->property) 时隐式调用。
注意,如果属性未定义,此方法将不做任何操作。如果属性是只读,它将抛出异常。
| public void __unset ( $name ) | ||
| $name | string |
属性名称 |
| throws | 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);
}
}
Defined in: yii\mail\MessageInterface::attach()
将现有文件附加到电子邮件消息。
| public abstract $this attach ( $fileName, array $options = [] ) | ||
| $fileName | string |
完整的文件名 |
| $options | array |
嵌入文件的选项。有效的选项是
|
| return | $this |
自身引用。 |
|---|---|---|
public function attach($fileName, array $options = []);
Defined in: yii\mail\MessageInterface::attachContent()
将指定的内容作为文件附加到电子邮件消息。
| public abstract $this attachContent ( $content, array $options = [] ) | ||
| $content | string |
附件文件内容。 |
| $options | array |
嵌入文件的选项。有效的选项是
|
| return | $this |
自身引用。 |
|---|---|---|
public function attachContent($content, array $options = []);
Defined in: yii\base\BaseObject::canGetProperty()
返回一个值,指示属性是否可读。
一个属性是可读的,如果
- 该类具有与指定名称关联的 getter 方法(在这种情况下,属性名称不区分大小写);
- 该类具有与指定名称相同的成员变量(当
$checkVars为 true 时);
另见 canSetProperty().
| public boolean canGetProperty ( $name, $checkVars = true ) | ||
| $name | string |
属性名称 |
| $checkVars | boolean |
是否将成员变量视为属性 |
| return | boolean |
属性是否可读 |
|---|---|---|
public function canGetProperty($name, $checkVars = true)
{
return method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name);
}
Defined in: yii\base\BaseObject::canSetProperty()
返回一个值,指示属性是否可写。
一个属性是可写的,如果
- 该类具有与指定名称关联的 setter 方法(在这种情况下,属性名称不区分大小写);
- 该类具有与指定名称相同的成员变量(当
$checkVars为 true 时);
另见 canGetProperty().
| public boolean canSetProperty ( $name, $checkVars = true ) | ||
| $name | string |
属性名称 |
| $checkVars | boolean |
是否将成员变量视为属性 |
| return | boolean |
属性是否可写 |
|---|---|---|
public function canSetProperty($name, $checkVars = true)
{
return method_exists($this, 'set' . $name) || $checkVars && property_exists($this, $name);
}
::class 代替。
Defined in: yii\base\BaseObject::className()
返回此类的完全限定名称。
| public static string className ( ) | ||
| return | string |
此类的完全限定名称。 |
|---|---|---|
public static function className()
{
return get_called_class();
}
| public abstract string embed ( $fileName, array $options = [] ) | ||
| $fileName | string |
文件名。 |
| $options | array |
嵌入文件的选项。有效的选项是
|
| return | string |
附件 CID。 |
|---|---|---|
public function embed($fileName, array $options = []);
| public abstract string embedContent ( $content, array $options = [] ) | ||
| $content | string |
附件文件内容。 |
| $options | array |
嵌入文件的选项。有效的选项是
|
| return | string |
附件 CID。 |
|---|---|---|
public function embedContent($content, array $options = []);
定义于: yii\mail\MessageInterface::getBcc()
返回此消息的密件抄送 (隐藏副本接收方) 地址。
| public abstract string|array getBcc ( ) | ||
| return | string|array |
此消息的密件抄送 (隐藏副本接收方) 地址。 |
|---|---|---|
public function getBcc();
定义于: yii\mail\MessageInterface::getCc()
返回此消息的抄送 (附加副本接收方) 地址。
| public abstract string|array getCc ( ) | ||
| return | string|array |
此消息的抄送 (附加副本接收方) 地址。 |
|---|---|---|
public function getCc();
定义于: yii\mail\MessageInterface::getCharset()
返回此消息的字符集。
| public abstract string getCharset ( ) | ||
| return | string |
此消息的字符集。 |
|---|---|---|
public function getCharset();
定义于: yii\mail\MessageInterface::getFrom()
返回消息发件人。
| public abstract string|array getFrom ( ) | ||
| return | string|array |
发件人 |
|---|---|---|
public function getFrom();
定义于: yii\mail\MessageInterface::getReplyTo()
返回此消息的回复地址。
| public abstract string|array getReplyTo ( ) | ||
| return | string|array |
此消息的回复地址。 |
|---|---|---|
public function getReplyTo();
定义于: yii\mail\MessageInterface::getSubject()
返回消息主题。
| public abstract string getSubject ( ) | ||
| return | string |
消息主题 |
|---|---|---|
public function getSubject();
定义于: yii\mail\MessageInterface::getTo()
返回消息接收方。
| public abstract string|array getTo ( ) | ||
| return | string|array |
消息接收方 |
|---|---|---|
public function getTo();
定义于: yii\base\BaseObject::hasMethod()
返回一个值,指示方法是否已定义。
默认实现是调用 php 函数 method_exists()。当您实现 php 魔术方法 __call() 时,您可能需要重写此方法。
| public boolean hasMethod ( $name ) | ||
| $name | string |
方法名称 |
| return | 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 |
是否将成员变量视为属性 |
| return | 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 是否已设置,如果没有,则将使用“邮件程序”应用程序组件。 |
| return | 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 |
隐藏副本收件人电子邮件地址。如果多个收件人应收到此消息,则可以传递地址数组。您还可以使用以下格式在电子邮件地址之外指定收件人姓名: |
| return | $this |
自身引用。 |
|---|---|---|
public function setBcc($bcc);
定义于: yii\mail\MessageInterface::setCc()
设置此消息的抄送 (附加副本接收方) 地址。
| public abstract $this setCc ( $cc ) | ||
| $cc | string|array |
抄送收件人电子邮件地址。如果多个收件人应收到此消息,则可以传递地址数组。您还可以使用以下格式在电子邮件地址之外指定收件人姓名: |
| return | $this |
自身引用。 |
|---|---|---|
public function setCc($cc);
定义于: yii\mail\MessageInterface::setCharset()
设置此消息的字符集。
| public abstract $this setCharset ( $charset ) | ||
| $charset | string |
字符集名称。 |
| return | $this |
自身引用。 |
|---|---|---|
public function setCharset($charset);
定义于: yii\mail\MessageInterface::setFrom()
设置消息发件人。
| public abstract $this setFrom ( $from ) | ||
| $from | string|array |
发件人电子邮件地址。如果您想从多人发送此消息,则可以传递地址数组。您还可以使用以下格式在电子邮件地址之外指定发件人姓名: |
| return | $this |
自身引用。 |
|---|---|---|
public function setFrom($from);
定义于: yii\mail\MessageInterface::setHtmlBody()
设置消息的 HTML 内容。
| public abstract $this setHtmlBody ( $html ) | ||
| $html | string |
消息的 HTML 内容。 |
| return | $this |
自身引用。 |
|---|---|---|
public function setHtmlBody($html);
定义于: yii\mail\MessageInterface::setReplyTo()
设置此消息的回复地址。
| public abstract $this setReplyTo ( $replyTo ) | ||
| $replyTo | string|array |
回复地址。如果您想将此消息回复给多人,则可以传递地址数组。您还可以使用以下格式在电子邮件地址之外指定回复地址: |
| return | $this |
自身引用。 |
|---|---|---|
public function setReplyTo($replyTo);
定义于: yii\mail\MessageInterface::setSubject()
设置消息主题。
| public abstract $this setSubject ( $subject ) | ||
| $subject | string |
消息主题 |
| return | $this |
自身引用。 |
|---|---|---|
public function setSubject($subject);
定义于: yii\mail\MessageInterface::setTextBody()
设置消息的纯文本内容。
| public abstract $this setTextBody ( $text ) | ||
| $text | string |
消息的纯文本内容。 |
| return | $this |
自身引用。 |
|---|---|---|
public function setTextBody($text);
定义于: yii\mail\MessageInterface::setTo()
设置消息接收方。
| public abstract $this setTo ( $to ) | ||
| $to | string|array |
收件人电子邮件地址。如果多个收件人应收到此消息,则可以传递地址数组。您还可以使用以下格式在电子邮件地址之外指定收件人姓名: |
| return | $this |
自身引用。 |
|---|---|---|
public function setTo($to);
定义于: yii\mail\MessageInterface::toString()
返回此消息的字符串表示形式。
| public abstract string toString ( ) | ||
| return | string |
此消息的字符串表示形式。 |
|---|---|---|
public function toString();
注册 或 登录 以发表评论。