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)) {
$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.";