Ich habe ein Skript, das regelmäßig (alle ~ 5 Minuten) fordert eine Reihe von Daten von einer API und sendet möglicherweise eine E-Mail.php - phpMailer Cron hinzufügen ist eine E-Mail an die Warteschlange, während es sollte nicht
Allerdings habe ich vor kurzem vom Server-Administrator kontaktiert, dass dort eine riesige Menge an Mails in der Warteschlange, die nie wegen der Cron gesendet werden.
Wie auch immer es jetzt aussieht, sollte es niemals die E-Mails senden, da es niemals die if-Anweisungen, in denen der Mailing-Code platziert ist, bestehen sollte.
Script mehr oder weniger tut die gleiche Sache zweimal, aber mit einigen verschiedenen E-Mails:
/* Paging - Every ~15 minutes, during non-working-times, for all dashboards that have pagerservice enabled. */
$queryPagerservice = mysqli_query($dbcon, "SELECT `id`, `text` FROM `dashboard` WHERE `pagerservice`=true AND (`last_pager` < NOW() - INTERVAL ".PAGER_INTERVAL." MINUTE OR `last_pager` IS NULL)");
$timeNow = date("Gi");
while ($pagerservice = mysqli_fetch_array($queryPagerservice, MYSQLI_ASSOC)) {
echo '1.'; //Does the script hit this code?
$issues = new Issues($pagerservice['id'], 'all', $dbcon);
$array = $issues->getIssues();
if ((count($array['aaData']) > 0) && ($timeNow > WORK_START && $timeNow < WORK_END)) {
mysqli_query($dbcon, "UPDATE `dashboard` SET `last_pager`=NOW() WHERE `id`='".$pagerservice['id']."'");
$date = date('d-m-Y H:i:s');
$message = "There are ".count($array['aaData'])." problems in '".$pagerservice['text']."'.";
echo '2.'; //Does the script hit this code?
require_once('phpmailer/PHPMailerAutoload.php');
$pagerMail = new PHPMailer;
$pagerMail->isSMTP();
$pagerMail->Host = MAILSERVER_ADDRESS;
$pagerMail->Port = MAILSERVER_PORT;
$pagerMail->setFrom('[email protected]', 'EXAMPLE Pager');
$pagerMail->addReplyTo('[email protected]', 'No Reply');
$pagerMail->addAddress(PAGE_EMAIL, 'pagerservice');
$pagerMail->addAddress(PAGER_PHONE.'@'.PAGER_PROVIDER, 'pagerservice');
$pagerMail->Subject = 'pagerservice';
$pagerMail->Body = $message;
$pagerMail->AltBody = $message;
$pagerMail->send();
}
}
/* Notifications - Every ~15 minutes, during working hours, for all dashboards that have notifications enabled. */
$queryNotification = mysqli_query($dbcon, "SELECT `id`, `text` FROM `dashboard` WHERE `notification`=true AND (`last_notification` < NOW() - INTERVAL ".NOTIF_INTERVAL." MINUTE OR `last_notification` IS NULL)");
$timeNow = date("Gi");
while ($notifications = mysqli_fetch_array($queryNotification, MYSQLI_ASSOC)) {
echo '3.'; //Does the script hit this code?
$issues = new Issues($notifications['id'], 'all', $dbcon);
$array = $issues->getIssues();
if ((count($array['aaData']) > 0) && ($timeNow > WORK_START && $timeNow < WORK_END)) {
mysqli_query($dbcon, "UPDATE `dashboard` SET `last_notification`=NOW() WHERE `id`='".$notifications['id']."'");
$date = date('d-m-Y H:i:s');
$message = "(Notif) There are ".count($array['aaData'])." problems in '".$pagerservice['text']."'.";
echo '4.'; //Does the script hit this code?
require_once('phpmailer/PHPMailerAutoload.php');
$notifMail = new PHPMailer;
$notifMail->isSMTP();
$notifMail->Host = MAILSERVER_ADDRESS;
$notifMail->Port = MAILSERVER_PORT;
$notifMail->setFrom('[email protected]', 'EXMAPLE Notificator');
$notifMail->addReplyTo('[email protected]', 'No Reply');
$notifMail->addAddress(NOTIF_EMAIL, 'notifications');
$notifMail->Subject = 'notification';
$notifMail->Body = $message;
$notifMail->AltBody = $message;
$notifMail->send();
}
}
Versuchte fix: ich den require_once()
Anruf innerhalb der if-Anweisung bewegt. Das hat es nicht behoben.
Es gibt keinen anderen Code im Skript, der sich auf das Senden von E-Mails bezieht. Und der Code, der E-Mail-bezogen ist, wird nicht ausgeführt (wie durch die Tatsache gezeigt wird, dass weder 1.
, 2.
, 3.
noch 1.
Echo ist).
Ich suche nach irgendwelchen Tipps, was dazu führen kann, dass das Cron-Skript eine E-Mail in eine Warteschlange stellt, die niemals vom SMTP-Server gesendet wird.
Persönlich würde ich um Klärung bitten, was das bedeutet. Wenn sich eine E-Mail in der SMTP-Warteschlange befindet, wird sie durch nichts, was der Cron später tut, beeinflusst. Wenn sich die E-Mails in der SMTP-Warteschlange befinden und nicht gesendet werden, liegt ein Problem mit dem SMTP-Server oder der Ziel-E-Mail-Adresse vor. – ChrisBint
@ChrisBint Jedes Mal, wenn der Cron ausgeführt wird, wird eine E-Mail zur SMTP-Warteschlange hinzugefügt, obwohl der Code, der dies verursachen könnte, nicht einmal ausgeführt wird. Ich werde bald um eine Klarstellung bitten. – kgongonowdoe