简体   繁体   English

如何使用Barbushin imap类按ID提取邮件

[英]How to fetch mail by id with barbushin imap class

I'm currently working on the imap class by barbushin . 我目前正在使用barbushin编写的imap类。 It's the only php class over the internet I can find regardless to any encoding issue. 这是我在互联网上可以找到的唯一php类,无论是否存在任何编码问题。 Thanks to the coder. 感谢编码器。

I have a list of messages in a table. 我在表中有邮件列表。 Each message sending a message id as GET (say $mid). 每条发送消息ID为GET的消息(例如$ mid)。 When a link clicked, the page turned into a view page. 单击链接后,页面变为查看页面。 It should open that message and display the relevant content right? 它应该打开该消息并显示相关内容,对吗? But it is not. 但事实并非如此。 Every message has the same content (the 1st content). 每个消息具有相同的内容(第一个内容)。 The code is designed for gmail but I use it for my client. 该代码是为gmail设计的,但我将其用于客户端。 And it's work. 这是工作。

This is a code: 这是一个代码:

require_once('../ImapMailbox.php');

define('EMAIL', 'my@domain.com');
define('PASSWORD', '*********');
define('ATTACHMENTS_DIR', dirname(__FILE__) . '/attachments');

$mailbox = new ImapMailbox('{imap.gmail.com:993/imap/ssl}INBOX', EMAIL, PASSWORD, ATTACHMENTS_DIR, 'utf-8');
$mails = array();

// Get some mail
$mailsIds = $mailbox->searchMailBox('ALL');
if(!$mailsIds) {
    die('Mailbox is empty');
}

$mailId = reset($mailsIds);
$mail = $mailbox->getMail($mailId);

var_dump($mail);
var_dump($mail->getAttachments());

The original is here: https://github.com/barbushin/php-imap 原文在这里: https : //github.com/barbushin/php-imap

Finally, I found my way home. 终于,我找到了回家的路。 According to the script there's a line says "mailId". 根据脚本,一行显示“ mailId”。 Which is straight forward what is it about. 这是直接的。

It was set to the first array by reset(). 它由reset()设置为第一个数组。 So the only thing I need to do is extract the message id from it ($mailId is an array of ids). 因此,我唯一需要做的就是从中提取消息ID($ mailId是ID数组)。 So I simply add an array behind it. 所以我只是在其后面添加一个数组。

$mailId=$mailsIds[$_GET[uid]];

While $_GET[uid] is a message id sent from a previous page. $_GET[uid]是从上一页发送的消息ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM