Jump to content

IMAP functions


Go to solution Solved by ginerjm,

Recommended Posts

Trying to use the imap functions to handle moving incoming mail from the INBOX to a separate folder. Read all kinds of stuff on the various functions to read the headers and such and now the move function is killing me.

 

I have studied my host's email configurations and the manuals references on how to make the connection but I am getting nowhere. Here's my connection string:

$mailbox = imap_open("{mydomain.net:993/imap/ssl/novalidate-cert}INBOX", $emailacct, $emlaccess);

 

I have tried several different ports and /switch choices and none work. The one I posted is the most often referenced so I show it to you.

 

The problem I keep getting is this error message:

 

Errors: Array

(

[0] => Client tried to access nonexistent

namespace. (Mailbox name should probably be prefixed with: INBOX.)

(0.000 + 0.000 secs).

)

 

As you can see my connection string doesn't use any other mailbox but INBOX so I don't understand the problem here. The error occurs right after trying to do the open, not later when I actually try to use imap_move_mail to move stuff from INBOX to a seperate folder, which btw is NOT underneath eh inbox.

 

Anyone out there used these functions before?

Edited by ginerjm
Link to comment
https://forums.phpfreaks.com/topic/302243-imap-functions/
Share on other sites

  • Solution

Problem solved. Found some new material and after a bit more experimenting got it all working.

 

For those interested:

 

To make an ssl connection using IMAP with no 'real' certificate use this:

$host = "{domain.net:993/ssl/novalidate-cert}INBOX";
$mailbox = imap_open($host, $emailaddr, $emlaccess);

 

I was using this in a script that was handling forwarded emails on STDIN so the following got me the current message #

$imap_obj = imap_check($mailbox);
$msg_cnt = $imap_obj->Nmsgs; // get last msg no. that we just processed

 

With the messge number I could then move the message out of the inbox to a specific destination folder that

I wanted to archive these emails in:

imap_mail_move($mailbox,$msg_cnt,$dest);

 

Note that my dest folder had to be named as follows:

 

INBOX.subfolder.subfolder

 

rather than how some parts of the manual said it had to be formatted.

 

Last but not least and as the manual did tell me, when you do a move like this the original message still sits in the inbox. You have to turn on the flag in the imap_close function to cause this message to be removed once the inbox is closed

 

imap_close($mailbox,CL_EXPUNGE);

 

Note the value is a Constant and needs no quotes.

 

This all had to be done as IMAP since one cannot do folder moves using POP3 apparently.

Link to comment
https://forums.phpfreaks.com/topic/302243-imap-functions/#findComment-1537856
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.