Strip out mail actions, replace with ntfy.sh

This commit is contained in:
Joshua Coles 2024-05-09 15:25:00 +01:00
parent 5fff7c59eb
commit d3a9bc8ca8

View File

@ -12,12 +12,6 @@
if ($row = $result->fetchArray(SQLITE3_ASSOC)) { if ($row = $result->fetchArray(SQLITE3_ASSOC)) {
$notificationsEnabled = $row['enabled']; $notificationsEnabled = $row['enabled'];
$days = $row['days']; $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 { } else {
echo "Notifications are disabled. No need to run."; echo "Notifications are disabled. No need to run.";
} }
@ -49,11 +43,6 @@
} }
if (!empty($notify)) { 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 = $db->prepare('SELECT * FROM user WHERE id = :id');
$stmt->bindValue(':id', 1, SQLITE3_INTEGER); $stmt->bindValue(':id', 1, SQLITE3_INTEGER);
$result = $stmt->execute(); $result = $stmt->execute();
@ -68,37 +57,18 @@
foreach ($perUser as $subscription) { foreach ($perUser as $subscription) {
$message .= $subscription['name'] . " for " . $subscription['price'] . "\n"; $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; $ntfy_title = 'Wallos Notification';
$name = !empty($user['name']) ? $user['name'] : $defaultName; $ntfy_body = $message;
file_get_contents('https://ntfy.sh/canvas-progress-east', false, stream_context_create([
$mail->setFrom($fromEmail, 'Wallos App'); 'http' => [
$mail->addAddress($email, $name); 'method' => 'POST', // PUT also works
'header' =>
$mail->Subject = 'Wallos Notification'; "Content-Type: text/plain\r\n" .
$mail->Body = $message; "Title: Subscription Alert",
'content' => $message
if ($mail->send()) { ]
echo "Notifications sent"; ]));
} else {
echo "Error sending notifications: " . $mail->ErrorInfo;
}
} }
} else { } else {
echo "Nothing to notify."; echo "Nothing to notify.";