Below is part of the script I am using to log all failed emails in the database. When I found the script, originally the 7th line (in the code at the bottom) looked like this:
for($x=1; $x < count($headers); $x++) {
It was just <, I added <= because it would originally read all of the messages in my inbox except the last one. When I changed it to <=, it would read all of the messages, but every so often I get an error saying "Warning: imap_body(): Bad message number in /home/mail.php on line 23" Any idea what I can do? My code is below.
$host = "localhost";
$user = "user";
$pass = "pass";
$MAILSERVER = "{".$host.":"."143}";
$link=imap_open ($bx, $user, $pass);
$headers=imap_headers($link);
for($x=1; $x <= count($headers); $x++) {
$errdate = time();
line 23 $body = stripslashes(imap_body($link, $x));
$insert = mysql_query("INSERT INTO failed_emails VALUES ('', '$body', '$errdate')");
imap_delete($link, $x);
imap_expunge ($link);
}