I've been trying to write a script to delete emails.  The server is an
exchange server, but I've been using imap to connect.  I have a script that
pulls the messages from today and then does some sorting/counting/etc of the
messages and then emails to results.  What I need to do now is delete the
emails that are in the inbox.  Ideally, if I could delete the messages that
are >1day old, but I'll take just deleting them all each day.  Obviously
these emails are not mission critical, they are emails that are sent to a
catch-all mailbox.  This is what I have come up with, but it doesn't work:

<?php
date_default_timezone_set('America/Denver');
$user = 'blah';
$password = 'blah-blah';
$connection = @imap_open("{mail.server.com:143/novalidate-cert}INBOX",
"$user", "$password");
$count = imap_num_msg($connection);

$headers = @imap_check($conn);
($headers->Nmsgs > 0) or die("Trash is empty already !");

// delete email(s)
  @imap_delete($connnection,'1:*');   // to clear out the entire mailbox.
  @imap_expunge($connection);

imap_close($connection, CL_EXPUNGE);
?>

It runs fine, doesn't throw any errors but it also doesn't delete any
messages.  Any suggestions?

Also, the connection string is the same connection string I use in the
script that works so I know it's connecting.

_______________________________________________

UPHPU mailing list
[email protected]
http://uphpu.org/mailman/listinfo/uphpu
IRC: #uphpu on irc.freenode.net

Reply via email to