forked from science-ation/science-ation
Fix email sending to not fail if a single email fails, instead, flag it as failed and continue on
Better track email sending as well, and add fields for tracking bounces (not implemented yet)
This commit is contained in:
parent
496c0400aa
commit
5dcbc28d54
@ -839,13 +839,20 @@ case "email_get_list":
|
||||
mysql_query("UPDATE emails SET lastsent=NOW() WHERE id='$emailid'");
|
||||
}
|
||||
launchQueue();
|
||||
|
||||
echo "<br />";
|
||||
echo happy("Email Communication sending has started!");
|
||||
echo "<br>";
|
||||
echo "<a href=\"communication_send_status.php\">Click here to see the sending progress</a>";
|
||||
|
||||
}
|
||||
else if($_GET['action']=="restartqueue")
|
||||
{
|
||||
launchQueue();
|
||||
echo "<br />";
|
||||
echo happy("Email Communication sending has started!");
|
||||
echo "<br>";
|
||||
echo "<a href=\"communication_send_status.php\">Click here to see the sending progress</a>";
|
||||
}
|
||||
else {
|
||||
if(!$config['fairmanageremail'])
|
||||
echo notice(i18n("Warning: The 'Fair Manager Email' has not been set in SFIAB Configuration / Configuration Variables / Global. Please set it. The 'Fair Manager Email' is the default 'From' address for all emails and without a 'From' address, no emails can be sent!"));
|
||||
|
@ -27,9 +27,19 @@
|
||||
user_auth_required('committee', 'admin');
|
||||
|
||||
if($_GET['action']=="status") {
|
||||
if($config['emailqueue_lock']) {
|
||||
$q=mysql_query("SELECT * FROM emailqueue WHERE finished IS NULL");
|
||||
|
||||
if($config['emailqueue_lock'] || mysql_num_rows($q)) {
|
||||
echo "<h4>".i18n("Active Send Queues")."</h4>\n";
|
||||
$q=mysql_query("SELECT *,UNIX_TIMESTAMP(started) AS ts FROM emailqueue WHERE finished IS NULL ORDER BY started DESC");
|
||||
|
||||
if(!$config['emailqueue_lock']) {
|
||||
echo error(i18n("It looks like there's emails waiting to send, but the sending process isnt running.").
|
||||
"<br />".
|
||||
"<a href=\"communication.php?action=restartqueue\">".i18n("Click here to manually restart the process")."</a>");
|
||||
}
|
||||
|
||||
|
||||
echo "<table class=\"tableview\">";
|
||||
echo "<tr>";
|
||||
echo " <th>".i18n("Name")."</th>\n";
|
||||
@ -48,13 +58,14 @@
|
||||
$remaining=$r->numtotal-$r->numsent;
|
||||
$now=time();
|
||||
$duration=$now-$r->ts;
|
||||
echo " <td align=\"center\">$r->numsent / $r->numtotal</td>\n";
|
||||
$num=$r->numsent+$r->numfailed;
|
||||
echo " <td align=\"center\">$num / $r->numtotal</td>\n";
|
||||
echo "<td>";
|
||||
echo format_duration($duration);
|
||||
echo "</td>";
|
||||
echo "<td>";
|
||||
if($r->numsent) {
|
||||
$emailspersecond=$r->numsent/$duration;
|
||||
if($r->numsent || $r->numfailed) {
|
||||
$emailspersecond=($r->numsent+$r->numfailed)/$duration;
|
||||
$remainingduration=$remaining/$emailspersecond;
|
||||
echo format_duration($remainingduration);
|
||||
}
|
||||
@ -85,6 +96,10 @@
|
||||
echo " <th>".i18n("Started")."</th>\n";
|
||||
echo " <th>".i18n("Finished")."</th>\n";
|
||||
echo " <th>".i18n("Total Emails")."</th>\n";
|
||||
echo " <th>".i18n("Success")."</th>\n";
|
||||
echo " <th>".i18n("Failed")."</th>\n";
|
||||
//FIXME: comment bounced until we implement it
|
||||
// echo " <th>".i18n("Bounced")."</th>\n";
|
||||
echo "</tr>\n";
|
||||
while($r=mysql_fetch_object($q)) {
|
||||
echo "<tr>";
|
||||
@ -93,6 +108,9 @@
|
||||
echo " <td>$r->started</td>\n";
|
||||
echo " <td>$r->finished</td>\n";
|
||||
echo " <td align=\"center\">$r->numtotal</td>\n";
|
||||
echo " <td align=\"center\">$r->numsent</td>\n";
|
||||
echo " <td align=\"center\">$r->numfailed</td>\n";
|
||||
//echo " <td align=\"center\">$r->numbounced</td>\n";
|
||||
echo "</tr>\n";
|
||||
}
|
||||
echo "</table>\n";
|
||||
|
@ -61,23 +61,31 @@ if(!$config['emailqueue_lock']) {
|
||||
}
|
||||
|
||||
|
||||
echo "$email->id,$r->id,$to\n";
|
||||
echo "$email->id,$r->id,$to: ";
|
||||
|
||||
$result=email_send_new($to,$email->from,$email->subject,$body,$bodyhtml);
|
||||
|
||||
if($result) {
|
||||
mysql_query("UPDATE emailqueue_recipients SET sent=NOW() WHERE id='$r->id'");
|
||||
mysql_query("UPDATE emailqueue_recipients SET sent=NOW(), `result`='ok' WHERE id='$r->id'");
|
||||
echo mysql_error();
|
||||
$newnumsent=$email->numsent+1;
|
||||
mysql_query("UPDATE emailqueue SET numsent=$newnumsent WHERE id='$email->id'");
|
||||
$rq=mysql_query("SELECT COUNT(*) AS num FROM emailqueue_recipients WHERE sent IS NULL AND emailqueue_id='$email->id'");
|
||||
$rr=mysql_fetch_object($rq);
|
||||
if($rr->num==0) {
|
||||
mysql_query("UPDATE emailqueue SET finished=NOW() WHERE id='$email->id'");
|
||||
}
|
||||
echo mysql_error();
|
||||
echo "ok\n";
|
||||
}
|
||||
else {
|
||||
echo "Sending failed!\n";
|
||||
break;
|
||||
mysql_query("UPDATE emailqueue_recipients SET `sent`=NOW(), `result`='failed' WHERE id='$r->id'");
|
||||
echo mysql_error();
|
||||
$newnumfailed=$email->numfailed+1;
|
||||
mysql_query("UPDATE emailqueue SET numfailed=$newnumfailed WHERE id='$email->id'");
|
||||
echo mysql_error();
|
||||
echo "failed\n";
|
||||
}
|
||||
//now check if we're done yet
|
||||
$rq=mysql_query("SELECT COUNT(*) AS num FROM emailqueue_recipients WHERE sent IS NULL AND emailqueue_id='$email->id'");
|
||||
$rr=mysql_fetch_object($rq);
|
||||
if($rr->num==0) {
|
||||
mysql_query("UPDATE emailqueue SET finished=NOW() WHERE id='$email->id'");
|
||||
}
|
||||
usleep(rand($sleepmin,$sleepmax));
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
160
|
||||
161
|
||||
|
3
db/db.update.161.sql
Normal file
3
db/db.update.161.sql
Normal file
@ -0,0 +1,3 @@
|
||||
ALTER TABLE `emailqueue` ADD `numfailed` INT NOT NULL DEFAULT '0';
|
||||
ALTER TABLE `emailqueue` ADD `numbounced` INT NOT NULL DEFAULT '0';
|
||||
ALTER TABLE `emailqueue_recipients` ADD `result` ENUM( 'ok', 'failed' ) NULL DEFAULT NULL
|
Loading…
Reference in New Issue
Block a user