New Email » '; ob_start(); printHeader("Email Queue", 1); ob_flush(); flush(); $r = ocsql_query("SELECT * FROM `" . OCC_TABLE_EMAIL_QUEUE . "` WHERE `sent` IS NULL AND `tries`<1") or err('Unable to retrieve queued messages'); $count = ocsql_num_rows($r); if (($count == 0) && (!isset($_GET['pass']) || !ctype_digit($_GET['pass']))) { print '

The queue is empty. View email log.

'; } else { if (isset($_GET['f']) && ctype_digit($_GET['f'])) { $failed = $_GET['f']; } else { $failed = 0; } $date = safeSQLstr(gmdate('Y-m-d H:i:s')); print '

' . ((isset($_GET['pass']) && ($_GET['pass'] == 1)) ? 'Remaining m' : 'M') . 'essages in queue: ' . $count . "

\n"; while ($l = ocsql_fetch_assoc($r)) { if ($l['tries'] >= 1) { continue; } // skip messages that have been tried already print 'Message ID ' . $l['id'] . ' (' . safeHTMLstr($l['to']) . ') ... '; ob_flush(); flush(); $set = "`tries`=" . ($l['tries'] + 1); if (oc_mail($l['to'], $l['subject'], $l['body'])) { print 'sent'; $set .= ", `sent`='" . $date . "'"; } else { print 'FAILED!!!'; if ($l['tries'] == 2) { // this will have been the third try print ' Too many tries, will not try again.'; } print ''; $failed++; } print "
\n"; $q = "UPDATE `" . OCC_TABLE_EMAIL_QUEUE . "` SET " . $set . " WHERE `id`=" . $l['id'] . " LIMIT 1"; if ( ! ocsql_query($q)) { // throw error so same message doesn't keep being sent ob_flush_end(); err('Unable to update status for message ID ' . $l['id'] . '. Troubleshoot before trying again.'); } // reload script if close to timeout if (oc_checkTimeout()) { print ' '; } } if ($failed == 0) { print '

All messages have been sent.

'; } else { print '

' . $failed . ' messages failed to be sent.

'; } print '

View email log (most recent batch of messages will appear at the top)

'; } ob_end_flush(); printFooter(); ?>