From d3a9bc8ca8ccf4ed2c2649ec581cffc690583612 Mon Sep 17 00:00:00 2001 From: Joshua Coles Date: Thu, 9 May 2024 15:25:00 +0100 Subject: [PATCH] Strip out mail actions, replace with ntfy.sh --- endpoints/cronjobs/sendnotifications.php | 52 +++++------------------- 1 file changed, 11 insertions(+), 41 deletions(-) diff --git a/endpoints/cronjobs/sendnotifications.php b/endpoints/cronjobs/sendnotifications.php index 2e27247..afc4806 100644 --- a/endpoints/cronjobs/sendnotifications.php +++ b/endpoints/cronjobs/sendnotifications.php @@ -12,12 +12,6 @@ if ($row = $result->fetchArray(SQLITE3_ASSOC)) { $notificationsEnabled = $row['enabled']; $days = $row['days']; - $smtpAddress = $row["smtp_address"]; - $smtpPort = $row["smtp_port"]; - $encryption = $row["encryption"]; - $smtpUsername = $row["smtp_username"]; - $smtpPassword = $row["smtp_password"]; - $fromEmail = $row["from_email"] ? $row["from_email"] : "wallos@wallosapp.com"; } else { echo "Notifications are disabled. No need to run."; } @@ -49,11 +43,6 @@ } if (!empty($notify)) { - - require $webPath . 'libs/PHPMailer/PHPMailer.php'; - require $webPath . 'libs/PHPMailer/SMTP.php'; - require $webPath . 'libs/PHPMailer/Exception.php'; - $stmt = $db->prepare('SELECT * FROM user WHERE id = :id'); $stmt->bindValue(':id', 1, SQLITE3_INTEGER); $result = $stmt->execute(); @@ -68,37 +57,18 @@ foreach ($perUser as $subscription) { $message .= $subscription['name'] . " for " . $subscription['price'] . "\n"; } - - $mail = new PHPMailer(true); - $mail->CharSet="UTF-8"; - $mail->isSMTP(); - - $mail->Host = $smtpAddress; - $mail->SMTPAuth = true; - $mail->Username = $smtpUsername; - $mail->Password = $smtpPassword; - $mail->SMTPSecure = $encryption; - $mail->Port = $smtpPort; - - $stmt = $db->prepare('SELECT * FROM household WHERE id = :userId'); - $stmt->bindValue(':userId', $userId, SQLITE3_INTEGER); - $result = $stmt->execute(); - $user = $result->fetchArray(SQLITE3_ASSOC); - $email = !empty($user['email']) ? $user['email'] : $defaultEmail; - $name = !empty($user['name']) ? $user['name'] : $defaultName; - - $mail->setFrom($fromEmail, 'Wallos App'); - $mail->addAddress($email, $name); - - $mail->Subject = 'Wallos Notification'; - $mail->Body = $message; - - if ($mail->send()) { - echo "Notifications sent"; - } else { - echo "Error sending notifications: " . $mail->ErrorInfo; - } + $ntfy_title = 'Wallos Notification'; + $ntfy_body = $message; + file_get_contents('https://ntfy.sh/canvas-progress-east', false, stream_context_create([ + 'http' => [ + 'method' => 'POST', // PUT also works + 'header' => + "Content-Type: text/plain\r\n" . + "Title: Subscription Alert", + 'content' => $message + ] + ])); } } else { echo "Nothing to notify.";