\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/plain; charset=UTF-8\r\n"; $opts = '-f noreply@4chan.org'; return mail($email, $subject, $message, $headers, $opts); } // --- // Cleanup expired entries to not keep plaintext emails for too long. $tbl = TBL; $ttl = (int)ENTRY_TTL; $sql = "DELETE FROM `$tbl` WHERE created_on <= DATE_SUB(NOW(), INTERVAL $ttl SECOND)"; $res = mysql_global_call($sql); if (!$res) { echo "DB error while pruning stale entries. Aborting\n"; exit(-1); } // Start sending mails $batch_size = (int)BATCH_SIZE; $sql = "SELECT id, email, token FROM `$tbl` ORDER BY id ASC LIMIT $batch_size"; $res = mysql_global_call($sql); if (!$res) { echo "DB error while fetching entries. Aborting\n"; exit(-1); } $sent_count = 0; $error_count = 0; while ($row = mysql_fetch_assoc($res)) { $id = (int)$row['id']; $email = $row['email']; $token = $row['token']; if (!$email || !$token) { $error_count++; continue; } $ret = send_email($email, $token); if ($ret) { $sent_count++; $sql = "DELETE FROM `$tbl` WHERE id = $id LIMIT 1"; mysql_global_call($sql); } else { $error_count++; } //usleep(10000); // 10ms } // --- fclose($run_lock); echo "[" . date('r') . "] - Mailer run finished: sent $sent_count, errors $error_count\n"; exit(0);