牛牛在线工具

imap_append()

收录 8868 个 PHP 函数,含用途说明与用法示例。

imap_append()

将邮件消息追加到指定邮箱中

函数名: imap_append() 适用版本: PHP 4 >= 4.0.2, PHP 5, PHP 7 用法: imap_append(resource $imap_stream, string $mailbox, string $message, string $options = null, string $internal_date = null): bool 解释:imap_append() 函数用于将邮件消息追加到指定邮箱中。该函数可以将已经存在于邮件消息中的头部信息和正文部分追加到指定邮箱。 参数: $imap_stream: 必需,IMAP 连接资源。 $mailbox: 必需,目标邮箱的名称。 $message: 必需,要追加的邮件消息。 $options: 可选,附加选项。可以是 "/novalidate-cert",用于禁用 SSL 证书验证。 $internal_date: 可选,指定邮件的内部日期。如果没有提供该参数,将使用当前日期和时间。 返回值:如果成功追加了邮件消息,则返回 true。如果失败,则返回 false。 示例: // 连接到 IMAP 服务器 $imap_server = "{imap.example.com:993/imap/ssl}"; $imap_user = "your_email@example.com"; $imap_password = "your_password"; $imap_stream = imap_open($imap_server, $imap_user, $imap_password); // 创建一个新的邮件消息 $message = "Subject: Test Email\r\n"; $message .= "From: sender@example.com\r\n"; $message .= "To: recipient@example.com\r\n"; $message .= "\r\n"; $message .= "This is a test email."; // 将邮件消息追加到指定邮箱 $mailbox = "INBOX"; if (imap_append($imap_stream, $mailbox, $message)) { echo "邮件消息成功追加到邮箱!"; } else { echo "追加邮件消息失败!"; } // 关闭 IMAP 连接 imap_close($imap_stream); 注意事项: 在使用 imap_append() 函数之前,需要先使用 imap_open() 函数连接到 IMAP 服务器。 追加的邮件消息必须符合 RFC 822 邮件消息格式。 若要禁用 SSL 证书验证,可以在 $options 参数中添加 "/novalidate-cert"。 如果没有指定 $internal_date 参数,则将使用当前日期和时间作为邮件的内部日期。 追加邮件消息时,需要确保目标邮箱存在并且用户有足够的权限进行追加操作。