类 Message
电子邮件消息类。
此类用于发送基于 https://www.rfc-editor.org/rfc/rfc2822.txt 中概述的标准的互联网消息格式。
常量
-
字符串EMAIL_PATTERN ¶'/^((?:[\\p{L}0-9.!#$%&\'*+\\/=?^_`{|}~-]+)*@[\\p{L}0-9-._]+)$/ui'保存用于电子邮件验证的正则表达式模式。
-
整数LINE_LENGTH_MUST ¶998行长度 - 不得超过 - RFC 2822 - 2.1.1
-
整数LINE_LENGTH_SHOULD ¶78行长度 - 不应超过 - RFC 2822 - 2.1.1
-
字符串MESSAGE_BOTH ¶'both'消息类型 - BOTH
-
字符串MESSAGE_HTML ¶'html'消息类型 - HTML
-
字符串MESSAGE_TEXT ¶'text'消息类型 - TEXT
属性摘要
-
$appCharset protected
字符串|空应用程序范围的字符集,用于编码头和主体
-
$attachments protected
数组<字符串, 数组>应该附加到电子邮件的文件列表。
-
$bcc protected
数组密件抄送
-
$boundary protected
字符串|空如果设置,则用于多部分 MIME 消息的边界。
-
$cc protected
数组抄送
-
$charset protected
字符串发送电子邮件正文的字符集。
-
$charset8bit protected
列表<字符串>8 位字符集
-
$contentTypeCharset protected
数组<字符串, 字符串>定义 Content-Type 字符集名称
-
$domain protected
字符串用于 messageId 生成的域名。需要为 CLI 邮件手动设置,因为 env('HTTP_HOST') 为空。
-
$emailFormat protected
字符串电子邮件应该以什么格式发送。
-
$emailFormatAvailable protected
列表<字符串>可用的发送格式。
-
$emailPattern protected
字符串|空用于电子邮件验证的正则表达式。
-
$from protected
数组发送电子邮件的邮件地址。
-
$headerCharset protected
字符串|空发送电子邮件头的字符集。如果为空,则使用 $charset 属性作为默认值。
-
$headers protected
数组用户定义头的关联数组。键将根据 RFC2822 第 4.7.5 节添加前缀 'X-'。
-
$htmlMessage protected
字符串HTML 消息。
-
$message protected
数组要发送的最终消息。
-
$messageId protected
字符串|布尔值消息 ID。
-
$priority protected
整数|空包含电子邮件的可选优先级。
-
$readReceipt protected
数组回执电子邮件。
-
$replyTo protected
数组收件人将回复的电子邮件列表。
-
$returnPath protected
数组如果出现任何错误,将使用的邮件地址,例如:
- 远程邮件服务器关闭
- 远程用户已超出配额
- 未知用户
-
$sender protected
数组发件人电子邮件。
-
$serializableProperties protected
列表<字符串>可以序列化的属性。
-
$subject protected
字符串电子邮件的主题。
-
$textMessage protected
字符串文本消息。
-
$to protected
数组电子邮件的收件人。
-
$transferEncoding protected
字符串|空使用的电子邮件传输编码。如果为空,则使用 $charset 属性来确定传输编码。
-
$transferEncodingAvailable protected
列表<字符串>可用于设置传输的编码。
方法摘要
-
__construct() public
构造函数
-
__serialize() public
用于序列化 Message 对象的魔术方法。
-
__unserialize() public
用于重建 Message 对象的魔术方法。
-
addAttachments() public
添加附件
-
addBcc() public
添加 "bcc" 地址。
-
addCc() public
添加 "cc" 地址。
-
addEmail() protected
添加电子邮件
-
addHeaders() public
为消息添加头
-
addReplyTo() public
添加 "Reply-To" 地址。
-
addTo() public
添加 "To" 地址。
-
attachFiles() protected
通过在边界内添加文件内容来附加非嵌入文件。
-
attachInlineFiles() protected
将内联/嵌入文件附加到消息。
-
createBoundary() protected
创建唯一的边界标识符
-
createFromArray() public
从序列化配置配置电子邮件实例对象。
-
decodeForHeader() protected
解码指定的字符串
-
encodeForHeader() protected
使用当前字符集编码指定的字符串。
-
encodeString() protected
如果 App.encoding 值不同且存在 mb_convert_encoding 函数,则将一个字符集的字符串转换为另一个字符集。
-
formatAddress() protected
格式化地址
-
generateMessage() protected
生成完整消息。
-
getAttachments() public
获取电子邮件消息的附件。
-
getBcc() public
获取 "bcc" 地址。
-
getBody() public
以数组形式获取生成的邮件正文。
-
getBodyHtml() public
获取消息的 HTML 正文。
-
getBodyString() public
以字符串形式获取生成的正文。
-
getBodyText() public
获取消息的文本正文。
-
getBodyTypes() public
获取此电子邮件消息中的正文类型。
-
getCc() public
获取 "cc" 地址。
-
getCharset() public
字符集获取器。
-
getContentTransferEncoding() 公共
根据设置的 transferEncoding 或 charset 返回 Content-Transfer Encoding 值。
-
getContentTypeCharset() 公共
返回 Content-Type 的 charset 值。
-
getDomain() 公共
获取域。
-
getEmailFormat() 公共
获取电子邮件格式。
-
getEmailPattern() 公共
EmailPattern 设置器/获取器
-
getFrom() 公共
获取“来自”地址。
-
getHeaderCharset() 公共
HeaderCharset 获取器。
-
getHeaders() 公共
获取标题列表。
-
getHeadersString() 公共
获取标题字符串。
-
getMessageId() 公共
获取消息 ID。
-
getOriginalSubject() 公共
获取原始主题(不进行编码)。
-
getPriority() 公共
获取优先级。
-
getReadReceipt() 公共
获取回执(Disposition-Notification-To 标头)。
-
getReplyTo() 公共
获取“回复”地址。
-
getReturnPath() 公共
获取回退路径。
-
getSender() 公共
获取“发件人”地址。有关完整解释,请参阅下面的 RFC 链接。
-
getSubject() 公共
获取主题。
-
getTo() 公共
获取“收件人”地址
-
getTransferEncoding() 公共
TransferEncoding 获取器。
-
jsonSerialize() 公共
将电子邮件对象序列化为可以本地序列化并重新使用以克隆此电子邮件实例的值。
-
readFile() 受保护
读取文件内容并返回文件的 base64 版本。
-
reset() 公共
重置所有内部变量,以便能够发送新电子邮件。
-
setAttachments() 公共
将附件添加到电子邮件消息中。
-
setBcc() 公共
设置“密件抄送”地址。
-
setBody() 公共
设置消息正文。
-
setBodyHtml() 公共
设置消息的 HTML 正文。
-
setBodyText() 公共
设置消息的文本正文。
-
setCc() 公共
设置“抄送”地址。
-
setCharset() 公共
Charset 设置器。
-
setConfig() 公共
设置此实例的配置。
-
setDomain() 公共
设置域。
-
setEmail() 受保护
设置电子邮件
-
setEmailFormat() 公共
设置电子邮件格式。
-
setEmailPattern() 公共
EmailPattern 设置器/获取器
-
setEmailSingle() 受保护
仅设置一个电子邮件
-
setFrom() 公共
设置“来自”地址。
-
setHeaderCharset() 公共
HeaderCharset 设置器。
-
setHeaders() 公共
设置消息的标头。
-
setMessageId() 公共
设置消息 ID。
-
setPriority() 公共
设置优先级。
-
setReadReceipt() 公共
设置回执(Disposition-Notification-To 标头)。
-
setReplyTo() 公共
设置“回复”地址。
-
setReturnPath() 公共
设置回退路径。
-
setSender() 公共
设置“发件人”地址。有关完整解释,请参阅下面的 RFC 链接。
-
setSubject() 公共
设置主题。
-
setTo() 公共
设置“收件人”地址。
-
setTransferEncoding() 公共
TransferEncoding 设置器。
-
validateEmail() 受保护
验证电子邮件地址
-
wrap() 受保护
包装消息以遵循 RFC 2822 - 2.1.1
方法详情
__construct() ¶ 公共
__construct(array<string, mixed>|null $config = null)
构造函数
参数
-
array<string, mixed>|null$config 可选 配置数组或从 app.php 加载配置的字符串
__unserialize() ¶ 公共
__unserialize(array $data): void
用于重建 Message 对象的魔术方法。
参数
-
array$data 数据数组。
返回
voidaddAttachments() ¶ 公共
addAttachments(array $attachments): $this
添加附件
参数
-
array$attachments 文件名数组。
返回
$this抛出
InvalidArgumentException另请参阅
addBcc() ¶ 公共
addBcc(array|string $email, string|null $name = null): $this
添加 "bcc" 地址。
参数
-
array|string$email 包含电子邮件的字符串,包含电子邮件作为键、名称作为值的数组,或包含电子邮件作为值的数组(没有名称)。
-
string|null$name 可选 名称
返回
$thisaddCc() ¶ 公共
addCc(array|string $email, string|null $name = null): $this
添加 "cc" 地址。
参数
-
array|string$email 包含电子邮件的字符串,包含电子邮件作为键、名称作为值的数组,或包含电子邮件作为值的数组(没有名称)。
-
string|null$name 可选 名称
返回
$thisaddEmail() ¶ 受保护
addEmail(string $varName, array|string $email, string|null $name): $this
添加电子邮件
参数
-
string$varName 属性名称
-
array|string$email 包含电子邮件的字符串,包含电子邮件作为键、名称作为值的数组,或包含电子邮件作为值的数组(没有名称)。
-
string|null$name 名称
返回
$this抛出
InvalidArgumentExceptionaddReplyTo() ¶ 公共
addReplyTo(array|string $email, string|null $name = null): $this
添加 "Reply-To" 地址。
参数
-
array|string$email 包含电子邮件的字符串,包含电子邮件作为键、名称作为值的数组,或包含电子邮件作为值的数组(没有名称)。
-
string|null$name 可选 名称
返回
$thisaddTo() ¶ 公共
addTo(array|string $email, string|null $name = null): $this
添加 "To" 地址。
参数
-
array|string$email 包含电子邮件的字符串,包含电子邮件作为键、名称作为值的数组,或包含电子邮件作为值的数组(没有名称)。
-
string|null$name 可选 名称
返回
$thisattachFiles() ¶ 受保护
attachFiles(string|null $boundary = null): list<string>
通过在边界内添加文件内容来附加非嵌入文件。
参数
-
string|null$boundary 可选 要使用的边界。如果为 null,将默认为 $this->boundary
返回
列表<字符串>attachInlineFiles() ¶ 受保护
attachInlineFiles(string|null $boundary = null): list<string>
将内联/嵌入文件附加到消息。
参数
-
string|null$boundary 可选 要使用的边界。如果为 null,将默认为 $this->boundary
返回
列表<字符串>createFromArray() ¶ 公共
createFromArray(array<string, mixed> $config): $this
从序列化配置配置电子邮件实例对象。
参数
-
array<string, mixed>$config 电子邮件配置数组。
返回
$thisdecodeForHeader() ¶ 受保护
decodeForHeader(string $text): string
解码指定的字符串
参数
-
string$text 要解码的字符串
返回
字符串encodeForHeader() ¶ 受保护
encodeForHeader(string $text): string
使用当前字符集编码指定的字符串。
参数
-
string$text 要编码的字符串
返回
字符串encodeString() ¶ 受保护
encodeString(string $text, string $charset): string
如果 App.encoding 值不同且存在 mb_convert_encoding 函数,则将一个字符集的字符串转换为另一个字符集。
参数
-
string$text 要转换的文本
-
string$charset 目标编码
返回
字符串formatAddress() ¶ 受保护
formatAddress(array $address): array
格式化地址
如果地址包含非字母数字/空格字符,它将被引用,因为诸如 : 和 , 之类的字符已知会在地址标头字段中导致问题。
参数
-
array$address 要格式化的地址。
返回
数组getBodyString() ¶ 公共
getBodyString(string $eol = "\r\n"): string
以字符串形式获取生成的正文。
参数
-
string$eol 可选 用于拼接的换行符字符串。
返回
字符串另请参阅
getContentTransferEncoding() ¶ public
getContentTransferEncoding(): string
根据设置的 transferEncoding 或 charset 返回 Content-Transfer Encoding 值。
返回
字符串getContentTypeCharset() ¶ public
getContentTypeCharset(): string
返回 Content-Type 的 charset 值。
检查回退/兼容性类型,包括针对旧版日语字符集的解决方法。
返回
字符串getHeaders() ¶ public
getHeaders(array<int|string, string> $include = []): array<string, string>
获取标题列表。
包括
发件人回复地址回执发件人地址收件人抄送密送主题
参数
-
array<int|string, string>$include 可选 标头列表。
返回
数组<字符串, 字符串>getHeadersString() ¶ public
getHeadersString(list<string> $include = [], string $eol = "\r\n", Closure|null $callback = null): string
获取标题字符串。
参数
-
list<string>$include 可选 标头列表。
-
string$eol 可选 用于连接标头的换行符字符串。
-
Closure|null$callback 可选 在字符串化之前对每个标头值运行的回调。
返回
字符串另请参阅
getSender() ¶ public
getSender(): array
获取“发件人”地址。有关完整解释,请参阅下面的 RFC 链接。
返回
数组链接
jsonSerialize() ¶ public
jsonSerialize(): array
将电子邮件对象序列化为可以本地序列化并重新使用以克隆此电子邮件实例的值。
返回
数组抛出
Exception当视图变量对象无法正确序列化时。
readFile() ¶ protected
readFile(Psr\Http\Message\UploadedFileInterface|string $file): string
读取文件内容并返回文件的 base64 版本。
参数
-
Psr\Http\Message\UploadedFileInterface|string$file 要读取的文件的绝对路径或 UploadedFileInterface 实例。
返回
字符串setAttachments() ¶ public
setAttachments(array $attachments): $this
将附件添加到电子邮件消息中。
附件可以根据您需要的控制程度以几种形式定义。
附加单个文件
$this->setAttachments('path/to/file');
使用不同的文件名附加文件
$this->setAttachments(['custom_name.txt' => 'path/to/file.txt']);
附加文件并指定其他属性
$this->setAttachments(['custom_name.png' => [
'file' => 'path/to/file',
'mimetype' => 'image/png',
'contentId' => 'abc123',
'contentDisposition' => false
]
]);
从字符串附加文件并指定其他属性
$this->setAttachments(['custom_name.png' => [
'data' => file_get_contents('path/to/file'),
'mimetype' => 'image/png'
]
]);
contentId 键允许您指定内嵌附件。在您的电子邮件文本中,您可以使用 <img src="cid:abc123"> 来内嵌显示图像。
contentDisposition 键允许您禁用 Content-Disposition 标头,这可以提高与 Outlook 电子邮件客户端的附件兼容性。
参数
-
array$attachments 文件名数组。
返回
$this抛出
InvalidArgumentExceptionsetBcc() ¶ public
setBcc(array|string $email, string|null $name = null): $this
设置“密件抄送”地址。
参数
-
array|string$email 包含电子邮件的字符串,包含电子邮件作为键、名称作为值的数组,或包含电子邮件作为值的数组(没有名称)。
-
string|null$name 可选 名称
返回
$thissetBody() ¶ public
setBody(array<string, string> $content): $this
设置消息正文。
参数
-
array<string, string>$content 内容数组,键为“text”和/或“html”,分别包含对应类型的字符串内容。
返回
$thissetBodyHtml() ¶ public
setBodyHtml(string $content): $this
设置消息的 HTML 正文。
参数
-
string$content 内容字符串
返回
$thissetBodyText() ¶ public
setBodyText(string $content): $this
设置消息的文本正文。
参数
-
string$content 内容字符串
返回
$thissetCc() ¶ public
setCc(array|string $email, string|null $name = null): $this
设置“抄送”地址。
参数
-
array|string$email 包含电子邮件的字符串,包含电子邮件作为键、名称作为值的数组,或包含电子邮件作为值的数组(没有名称)。
-
string|null$name 可选 名称
返回
$thissetCharset() ¶ public
setCharset(string $charset): $this
Charset 设置器。
参数
-
string$charset 字符集。
返回
$thissetConfig() ¶ public
setConfig(array<string, mixed> $config): $this
设置此实例的配置。
参数
-
array<string, mixed>$config 配置数组。
返回
$thissetDomain() ¶ public
setDomain(string $domain): $this
设置域。
域作为顶级(@ 之后的部分)。
参数
-
string$domain 手动设置 CLI 邮件的域。
返回
$thissetEmail() ¶ protected
setEmail(string $varName, array|string $email, string|null $name): $this
设置电子邮件
参数
-
string$varName 属性名称
-
array|string$email 包含电子邮件的字符串,包含电子邮件作为键、名称作为值的数组,或包含电子邮件作为值的数组(没有名称)。
-
string|null$name 名称
返回
$this抛出
InvalidArgumentExceptionsetEmailFormat() ¶ public
setEmailFormat(string $format): $this
设置电子邮件格式。
参数
-
string$format 格式化字符串。
返回
$this抛出
InvalidArgumentExceptionsetEmailPattern() ¶ public
setEmailPattern(string|null $regex): $this
EmailPattern 设置器/获取器
参数
-
string|null$regex 用于电子邮件地址验证的模式,为 null 则取消设置模式并使用 filter_var()。
返回
$thissetEmailSingle() ¶ protected
setEmailSingle(string $varName, array|string $email, string|null $name, string $throwMessage): $this
仅设置一个电子邮件
参数
-
string$varName 属性名称
-
array|string$email 包含电子邮件的字符串,包含电子邮件作为键、名称作为值的数组,或包含电子邮件作为值的数组(没有名称)。
-
string|null$name 名称
-
string$throwMessage 异常消息
返回
$this抛出
InvalidArgumentExceptionsetFrom() ¶ public
setFrom(array|string $email, string|null $name = null): $this
设置“来自”地址。
参数
-
array|string$email 包含电子邮件的字符串,包含电子邮件作为键、名称作为值的数组,或包含电子邮件作为值的数组(没有名称)。
-
string|null$name 可选 名称
返回
$this抛出
InvalidArgumentExceptionsetHeaderCharset() ¶ public
setHeaderCharset(string|null $charset): $this
HeaderCharset 设置器。
参数
-
string|null$charset 字符集。
返回
$thissetHeaders() ¶ public
setHeaders(array $headers): $this
设置消息的标头。
参数
-
array$headers 包含要设置的标头的关联数组。
返回
$thissetMessageId() ¶ public
setMessageId(string|bool $message): $this
设置消息 ID。
参数
-
string|bool$message 如果为真,则生成新的 Message-ID,如果为假,则忽略(不发送到电子邮件),如果为字符串,则设置为 Message-ID。
返回
$this抛出
InvalidArgumentExceptionsetPriority() ¶ public
setPriority(int|null $priority): $this
设置优先级。
参数
-
int|null$priority 1(最高)到 5(最低)。
返回
$thissetReadReceipt() ¶ public
setReadReceipt(array|string $email, string|null $name = null): $this
设置回执(Disposition-Notification-To 标头)。
参数
-
array|string$email 包含电子邮件的字符串,包含电子邮件作为键、名称作为值的数组,或包含电子邮件作为值的数组(没有名称)。
-
string|null$name 可选 名称
返回
$this抛出
InvalidArgumentExceptionsetReplyTo() ¶ public
setReplyTo(array|string $email, string|null $name = null): $this
设置“回复”地址。
参数
-
array|string$email 包含电子邮件的字符串,包含电子邮件作为键、名称作为值的数组,或包含电子邮件作为值的数组(没有名称)。
-
string|null$name 可选 名称
返回
$this抛出
InvalidArgumentExceptionsetReturnPath() ¶ public
setReturnPath(array|string $email, string|null $name = null): $this
设置回退路径。
参数
-
array|string$email 包含电子邮件的字符串,包含电子邮件作为键、名称作为值的数组,或包含电子邮件作为值的数组(没有名称)。
-
string|null$name 可选 名称
返回
$this抛出
InvalidArgumentExceptionsetSender() ¶ public
setSender(array|string $email, string|null $name = null): $this
设置“发件人”地址。有关完整解释,请参阅下面的 RFC 链接。
参数
-
array|string$email 包含电子邮件的字符串,包含电子邮件作为键、名称作为值的数组,或包含电子邮件作为值的数组(没有名称)。
-
string|null$name 可选 名称
返回
$this抛出
InvalidArgumentException链接
setTo() ¶ public
setTo(array|string $email, string|null $name = null): $this
设置“收件人”地址。
参数
-
array|string$email 包含电子邮件的字符串,包含电子邮件作为键、名称作为值的数组,或包含电子邮件作为值的数组(没有名称)。
-
string|null$name 可选 名称
返回
$thissetTransferEncoding() ¶ public
setTransferEncoding(string|null $encoding): $this
TransferEncoding 设置器。
参数
-
string|null$encoding 设置的编码。
返回
$this抛出
InvalidArgumentExceptionvalidateEmail() ¶ protected
validateEmail(string $email, string $context): void
验证电子邮件地址
参数
-
string$email 要验证的电子邮件地址。
-
string$context 设置了哪个属性。
返回
void抛出
InvalidArgumentException如果电子邮件地址验证失败。
wrap() ¶ protected
wrap(string|null $message = null, int $wrapLength = self::LINE_LENGTH_MUST): list<string>
包装消息以遵循 RFC 2822 - 2.1.1
参数
-
string|null$message optional 要包装的消息。
-
int$wrapLength optional 行长。
返回
列表<字符串>属性详细信息
$emailPattern ¶ protected
用于电子邮件验证的正则表达式。
如果为 null,将使用 filter_var()。使用 emailPattern() 方法设置自定义模式。
类型
字符串|空