From 669dd6f482acb6243989fa40d41ce8ba822a8b0b Mon Sep 17 00:00:00 2001 From: M_Viper Date: Sun, 25 Feb 2024 15:28:37 +0000 Subject: [PATCH] Dateien nach "/" hochladen --- send_notifications.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 send_notifications.php diff --git a/send_notifications.php b/send_notifications.php new file mode 100644 index 0000000..fcab1c0 --- /dev/null +++ b/send_notifications.php @@ -0,0 +1,40 @@ +connect_error) { + die("Verbindung zur Datenbank fehlgeschlagen: " . $conn->connect_error); +} + +// Aktuelles Datum und Zeit abrufen +$current_datetime = date("Y-m-d H:i:s"); + +// Benachrichtigungsgrenze berechnen (13 Uhr) +$notification_datetime = date("Y-m-d 13:00:00"); + +// Nur weitermachen, wenn es nach 13 Uhr ist +if ($current_datetime >= $notification_datetime) { + // SQL-Abfrage vorbereiten + $sql = "SELECT * FROM materials WHERE expiration_date <= DATE_ADD(CURDATE(), INTERVAL notification_days DAY)"; + + $result = $conn->query($sql); + + if ($result->num_rows > 0) { + // E-Mails für ablaufende Artikel senden + while($row = $result->fetch_assoc()) { + $to = $row["email"]; + $subject = 'Artikel Ablaufbenachrichtigung'; + $message = 'Der Artikel ' . $row["item_name"] . ' mit Barcode ' . $row["barcode"] . ' läuft am ' . $row["expiration_date"] . ' ab.'; + $headers = 'From: noreply@viper.com' . "\r\n" . + 'Reply-To: noreply@viper.com' . "\r\n" . + 'X-Mailer: PHP/' . phpversion(); + + mail($to, $subject, $message, $headers); + } + } +} + +$conn->close(); +?>