PHP code to Read Sent Items from an Email Account

2019-08-02 02:24发布

问题:

I need to read sent items from an email account to insert the details into a database as part of development of a support ticket system.

I have managed to implement reading inbox emails using the below code and successfully inserted those into the database.

$stream = @imap_open($current_mailbox['mailbox'], $current_mailbox['username'], $current_mailbox['password']);
$overview = imap_fetch_overview($stream,$email_id,0);
$message = imap_fetchbody($stream,$email_id, 1.2);

I have searched all over the internet and stackoverflow to find a solution, but no use. I haven't found even a single discussion regarding this (Reading sent items from an email account).

Hope someone here can help me in this issue by sharing some useful code snippets or URLs for reference.

Thanks in advance.

回答1:

Got it working and successfully retrieved all sent emails by replacing {mail.domain.com:143/notls} with {mail.domain.com:143/notls}INBOX.Sent.

That is by setting the value of $current_mailbox['mailbox'] to {mail.remanns.com:143/notls}INBOX.Sent

The complete code is

$mailboxes = array(
    array(
        'label'     => 'domain.com',
        'enable'    => true,
        'mailbox'   => '{mail.domain.com:143/notls}INBOX.Sent',
        'username'  => 'mail@domain.com',
        'password'  => 'mypassword'
    )
);

$stream = @imap_open($current_mailbox['mailbox'], $current_mailbox['username'], $current_mailbox['password']);

Thank you Darren for guiding me through the right path. I figured it out by following you suggestion regarding finding the sent box name first.