简体   繁体   中英

How to fetch mail by id with barbushin imap class

I'm currently working on the imap class by barbushin . It's the only php class over the internet I can find regardless to any encoding issue. Thanks to the coder.

I have a list of messages in a table. Each message sending a message id as GET (say $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. 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

Finally, I found my way home. According to the script there's a line says "mailId". Which is straight forward what is it about.

It was set to the first array by reset(). So the only thing I need to do is extract the message id from it ($mailId is an array of ids). So I simply add an array behind it.

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

While $_GET[uid] is a message id sent from a previous page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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