CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 商业解决方案
  • 纪念品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与进来
    • 问题 (Github)
    • 烘焙坊
    • 精选资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 新闻通讯
    • 领英
    • YouTube
    • 脸书
    • 推特
    • Mastodon
    • 帮助和支持
    • 论坛
    • Stack Overflow
    • IRC
    • Slack
    • 付费支持
CakePHP

C CakePHP 5.1 Chiffon API

  • 项目
    • CakePHP
      • CakePHP
      • Chronos
      • Elastic Search
      • 队列
  • 版本
    • 5.1
      • 5.1
      • 5.0
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

命名空间

  • 全局
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
      • Exception
      • Transport
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

类 SmtpTransport

使用 SMTP 协议发送邮件

命名空间: Cake\Mailer\Transport

常量

  • AUTH_LOGIN ¶
    'LOGIN'
  • AUTH_PLAIN ¶
    'PLAIN'
  • AUTH_XOAUTH2 ¶
    'XOAUTH2'
  • SUPPORTED_AUTH_TYPES ¶
    [self::AUTH_PLAIN, self::AUTH_LOGIN, self::AUTH_XOAUTH2]

属性概览

  • $_config protected
    array<string, mixed>

    运行时配置

  • $_configInitialized protected
    bool

    配置属性是否已使用默认值进行配置

  • $_content protected
    array<string, string>

    要返回的电子邮件内容

  • $_defaultConfig protected
    array<string, mixed>

    此类的默认配置

  • $_lastResponse protected
    array

    最后发送的 SMTP 命令的响应。

  • $_socket protected
    Cake\Network\Socket

    到 SMTP 服务器的套接字

  • $authType protected
    string|null

    身份验证类型。

方法概览

  • __construct() public

    构造函数

  • __destruct() public

    析构函数

  • __wakeup() public

    反序列化处理程序。

  • _auth() protected

    发送身份验证

  • _authLogin() protected

    使用 AUTH LOGIN 机制进行身份验证。

  • _authPlain() protected

    使用 AUTH PLAIN 机制进行身份验证。

  • _authXoauth2() protected

    使用 AUTH XOAUTH2 机制进行身份验证。

  • _bufferResponseLines() protected

    解析并将响应行存储在 'code' => 'message' 格式中。

  • _configDelete() protected

    删除单个配置键。

  • _configRead() protected

    读取配置键。

  • _configWrite() protected

    写入配置键。

  • _connect() protected

    连接到 SMTP 服务器

  • _disconnect() protected

    断开连接

  • _generateSocket() protected

    用于生成套接字的辅助方法

  • _parseAuthType() protected

    解析最后一条响应行并提取首选身份验证类型。

  • _prepareFromAddress() protected

    准备 from 电子邮件地址。

  • _prepareFromCmd() protected

    准备 MAIL FROM SMTP 命令。

  • _prepareMessage() protected

    准备消息主体。

  • _prepareRcptCmd() protected

    准备 RCPT TO SMTP 命令。

  • _prepareRecipientAddresses() protected

    准备收件人电子邮件地址。

  • _sendData() protected

    发送数据

  • _sendRcpt() protected

    发送电子邮件

  • _smtpSend() protected

    用于将数据发送到 SMTP 连接的受保护方法

  • checkRecipient() protected

    检查是否至少设置了一个目标标头。

  • configShallow() public

    将提供的配置与现有配置合并。与 config() 对嵌套键执行递归合并不同,此方法执行简单合并。

  • connect() public

    连接到 SMTP 服务器。

  • connected() public

    检查到 SMTP 服务器的开放连接是否可用。

  • disconnect() public

    与 SMTP 服务器断开连接。

  • getConfig() public

    返回配置。

  • getConfigOrFail() public

    返回此特定键的配置。

  • getLastResponse() public

    返回最后发送的 SMTP 命令的响应。

  • send() public

    发送邮件

  • setConfig() public

    设置配置。

方法详情

__construct() ¶ public

__construct(array<string, mixed> $config = [])

构造函数

参数
array<string, mixed> $config optional

配置选项。

__destruct() ¶ public

__destruct()

析构函数

尝试断开连接以确保在套接字关闭之前正确终止连接。

__wakeup() ¶ public

__wakeup(): void

反序列化处理程序。

确保套接字属性不会以损坏的状态重新初始化。

返回
void

_auth() ¶ protected

_auth(): void

发送身份验证

返回
void
抛出
Cake\Network\Exception\SocketException

_authLogin() ¶ protected

_authLogin(string $username, string $password): void

使用 AUTH LOGIN 机制进行身份验证。

参数
string $username

用户名。

string $password

密码。

返回
void

_authPlain() ¶ protected

_authPlain(string $username, string $password): string|null

使用 AUTH PLAIN 机制进行身份验证。

参数
string $username

用户名。

string $password

密码。

返回
string|null

_authXoauth2() ¶ protected

_authXoauth2(string $username, string $token): void

使用 AUTH XOAUTH2 机制进行身份验证。

参数
string $username

用户名。

string $token

令牌。

返回
void
另请参阅
https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth#smtp-protocol-exchange
https://developers.google.com/gmail/imap/xoauth2-protocol#smtp_protocol_exchange

_bufferResponseLines() ¶ protected

_bufferResponseLines(list<string> $responseLines): void

解析并将响应行存储在 'code' => 'message' 格式中。

参数
list<string> $responseLines

要解析的响应行。

返回
void

_configDelete() ¶ protected

_configDelete(string $key): void

删除单个配置键。

参数
string $key

要删除的键。

返回
void
抛出
Cake\Core\Exception\CakeException
如果尝试覆盖现有配置

_configRead() ¶ protected

_configRead(string|null $key): mixed

读取配置键。

参数
string|null $key

要读取的键。

返回
mixed

_configWrite() ¶ protected

_configWrite(array<string, mixed>|string $key, mixed $value, string|bool $merge = false): void

写入配置键。

参数
array<string, mixed>|string $key

要写入的键。

mixed $value

要写入的值。

string|bool $merge 可选

如果为 true,则递归合并;如果为 'shallow',则简单合并;如果为 false,则覆盖,默认为 false。

返回
void
抛出
Cake\Core\Exception\CakeException
如果尝试覆盖现有配置

_connect() ¶ 受保护

_connect(): void

连接到 SMTP 服务器

返回
void
抛出
Cake\Network\Exception\SocketException

_disconnect() ¶ 受保护

_disconnect(): void

断开连接

返回
void
抛出
Cake\Network\Exception\SocketException

_generateSocket() ¶ 受保护

_generateSocket(): void

用于生成套接字的辅助方法

返回
void
抛出
Cake\Network\Exception\SocketException

_parseAuthType() ¶ 受保护

_parseAuthType(): void

解析最后一条响应行并提取首选身份验证类型。

返回
void

_prepareFromAddress() ¶ 受保护

_prepareFromAddress(Cake\Mailer\Message $message): array

准备 from 电子邮件地址。

参数
Cake\Mailer\Message $message

消息实例。

返回
array

_prepareFromCmd() ¶ 受保护

_prepareFromCmd(string $message): string

准备 MAIL FROM SMTP 命令。

参数
string $message

用于命令的发送电子邮件地址。

返回
string

_prepareMessage() ¶ 受保护

_prepareMessage(Cake\Mailer\Message $message): string

准备消息主体。

参数
Cake\Mailer\Message $message

消息实例。

返回
string

_prepareRcptCmd() ¶ 受保护

_prepareRcptCmd(string $message): string

准备 RCPT TO SMTP 命令。

参数
string $message

用于命令的发送电子邮件地址。

返回
string

_prepareRecipientAddresses() ¶ 受保护

_prepareRecipientAddresses(Cake\Mailer\Message $message): array

准备收件人电子邮件地址。

参数
Cake\Mailer\Message $message

消息实例。

返回
array

_sendData() ¶ 受保护

_sendData(Cake\Mailer\Message $message): void

发送数据

参数
Cake\Mailer\Message $message

消息实例。

返回
void
抛出
Cake\Network\Exception\SocketException

_sendRcpt() ¶ 受保护

_sendRcpt(Cake\Mailer\Message $message): void

发送电子邮件

参数
Cake\Mailer\Message $message

消息实例。

返回
void
抛出
Cake\Network\Exception\SocketException

_smtpSend() ¶ 受保护

_smtpSend(string|null $data, string|false $checkCode = '250'): string|null

用于将数据发送到 SMTP 连接的受保护方法

参数
string|null $data

要发送到 SMTP 服务器的数据。

string|false $checkCode 可选

要在服务器响应中检查的代码,如果为 false,则跳过。

返回
string|null
抛出
Cake\Network\Exception\SocketException

checkRecipient() ¶ 受保护

checkRecipient(Cake\Mailer\Message $message): void

检查是否至少设置了一个目标标头。

参数
Cake\Mailer\Message $message

消息实例。

返回
void
抛出
Cake\Core\Exception\CakeException
如果 to、cc 或 bcc 中至少有一个未指定。

configShallow() ¶ 公共

configShallow(array<string, mixed>|string $key, mixed|null $value = null): $this

将提供的配置与现有配置合并。与 config() 对嵌套键执行递归合并不同,此方法执行简单合并。

设置特定值。

$this->configShallow('key', $value);

设置嵌套值。

$this->configShallow('some.nested.key', $value);

同时更新多个配置设置。

$this->configShallow(['one' => 'value', 'another' => 'value']);
参数
array<string, mixed>|string $key

要设置的键,或完整的配置数组。

mixed|null $value 可选

要设置的值。

返回
$this

connect() ¶ 公共

connect(): void

连接到 SMTP 服务器。

此方法仅在没有可用连接的情况下尝试连接。

返回
void

connected() ¶ 公共

connected(): bool

检查到 SMTP 服务器的开放连接是否可用。

返回
bool

disconnect() ¶ 公共

disconnect(): void

与 SMTP 服务器断开连接。

此方法仅在有可用连接的情况下尝试断开连接。

返回
void

getConfig() ¶ 公共

getConfig(string|null $key = null, mixed $default = null): mixed

返回配置。

用法

读取整个配置。

$this->getConfig();

读取特定值。

$this->getConfig('key');

读取嵌套值。

$this->getConfig('some.nested.key');

使用默认值读取。

$this->getConfig('some-key', 'default-value');
参数
string|null $key 可选

要获取的键,或获取整个配置的 null。

mixed $default 可选

键不存在时的返回值。

返回
mixed

getConfigOrFail() ¶ 公共

getConfigOrFail(string $key): mixed

返回此特定键的配置。

此键的配置值必须存在,不能为 null。

参数
string $key

要获取的键。

返回
mixed
抛出
InvalidArgumentException

getLastResponse() ¶ 公共

getLastResponse(): array

返回最后发送的 SMTP 命令的响应。

响应包含一个或多个包含响应代码和可选响应消息文本的行。

[
    [
        'code' => '250',
        'message' => 'mail.example.com'
    ],
    [
        'code' => '250',
        'message' => 'PIPELINING'
    ],
    [
        'code' => '250',
        'message' => '8BITMIME'
    ],
    // etc...
]
返回
array

send() ¶ 公共

send(Cake\Mailer\Message $message): array{headers: string, message: string}

发送邮件

参数
Cake\Mailer\Message $message

消息实例。

返回
array{headers: string, message: string}
抛出
Cake\Network\Exception\SocketException

setConfig() ¶ 公共

setConfig(array<string, mixed>|string $key, mixed|null $value = null, bool $merge = true): $this

设置配置。

用法

设置特定值。

$this->setConfig('key', $value);

设置嵌套值。

$this->setConfig('some.nested.key', $value);

同时更新多个配置设置。

$this->setConfig(['one' => 'value', 'another' => 'value']);
参数
array<string, mixed>|string $key

要设置的键,或完整的配置数组。

mixed|null $value 可选

要设置的值。

bool $merge 可选

是否递归合并或覆盖现有配置,默认为 true。

返回
$this
抛出
Cake\Core\Exception\CakeException
当尝试设置无效键时。

属性详情

$_config ¶ 受保护

运行时配置

类型
array<string, mixed>

$_configInitialized ¶ 受保护

配置属性是否已使用默认值进行配置

类型
bool

$_content ¶ 受保护

要返回的电子邮件内容

类型
array<string, string>

$_defaultConfig ¶ 受保护

此类的默认配置

类型
array<string, mixed>

$_lastResponse ¶ 受保护

最后发送的 SMTP 命令的响应。

类型
array

$_socket ¶ 受保护

到 SMTP 服务器的套接字

类型
Cake\Network\Socket

$authType ¶ 受保护

身份验证类型。

类型
string|null
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与进来
  • 问题 (Github)
  • 烘焙坊
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 新闻通讯
  • 领英
  • YouTube
  • 脸书
  • 推特
  • Mastodon
  • 帮助和支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成