WordPress wp-mail.php command failed error

I use wordpress post via email feature, and use default script, wp-mail.php which connects to emailbox, reads emails and posts them into blog.
Almost everything was working OK, untill I noticed lots of dublicated posts.

I tried to run the file directly, and almost all posts were ok, but script stucked on one post(email message).  I reloaded the script(wp-mail.php). The results was the same. Script read all the messages AGAIN, and stuck on the same post again, with the error:  Oops POP3 delete: Command failed . Reloaded again. The same result again. This way I inserted triple posts :D And mailbox was not cleaned, the inserted messages were not deleted.

I’ve made a simple solution. WP-mail.php closes POP3 session and quits:

if(!$pop3->delete($i)) {
echo ‘<p>’ . sprintf(__(‘Oops: %s’), esc_html($pop3->ERROR)) . ‘</p>’;
$pop3->reset();
exit;
}

POP3 reset command resets any messages which have been marked as read or deleted to the standard unread state. So they will be posted again on the next POP3 session. I decided to make it easy way. Instead of reset messages, I forced quit command:

if(!$pop3->delete($i)) {
echo ‘<p>’ . sprintf(__(‘Oops: %s’), esc_html($pop3->ERROR)) . ‘</p>’;
$pop3->quit(); /* forced quit without reset */
exit;
}

As far as all read messages on session quit are deleted, I got rid off that stuck errors. And that error post is NOT inserted into my blog.

I hope this may help save some time to other bloggers. If this file is overwritten when updating wordpress, you need to modify wp-mail.php again.

This solution may be valid only if you have many messages, and only sometimes this error occurs. If you get this error on ALL messages, I suppose this solution it NOT for your case, as there are some other errors, like possible message formatting, character encoding errors.

This entry was posted in PHP tips. Bookmark the permalink.

Leave a Reply