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();
@ -69,36 +58,17 @@
$message .= $subscription['name'] . " for " . $subscription['price'] . "\n"; $message .= $subscription['name'] . " for " . $subscription['price'] . "\n";
} }
$mail = new PHPMailer(true); $ntfy_title = 'Wallos Notification';
$mail->CharSet="UTF-8"; $ntfy_body = $message;
$mail->isSMTP(); file_get_contents('https://ntfy.sh/canvas-progress-east', false, stream_context_create([
'http' => [
$mail->Host = $smtpAddress; 'method' => 'POST', // PUT also works
$mail->SMTPAuth = true; 'header' =>
$mail->Username = $smtpUsername; "Content-Type: text/plain\r\n" .
$mail->Password = $smtpPassword; "Title: Subscription Alert",
$mail->SMTPSecure = $encryption; 'content' => $message
$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;
}
} }
} else { } else {
echo "Nothing to notify."; echo "Nothing to notify.";