Added option to set From email on smtp settings
This commit is contained in:
parent
c70859e1b0
commit
0b6246b09d
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/db/
|
||||
/images/uploads/logos/
|
||||
@ -16,6 +16,7 @@
|
||||
$smtpPort = $row["smtp_port"];
|
||||
$smtpUsername = $row["smtp_username"];
|
||||
$smtpPassword = $row["smtp_password"];
|
||||
$fromEmail = $row["fromEmail"] ?? "wallos@wallosapp.com";
|
||||
} else {
|
||||
echo "Notifications are disabled. No need to run.";
|
||||
}
|
||||
@ -70,7 +71,7 @@
|
||||
$email = $user['email'];
|
||||
$name = $user['username'];
|
||||
|
||||
$mail->setFrom('wallos@wallosapp.com', 'Wallos App');
|
||||
$mail->setFrom($fromEmail, 'Wallos App');
|
||||
$mail->addAddress($email, $name);
|
||||
|
||||
$mail->Subject = 'Wallos Notification';
|
||||
|
||||
@ -30,6 +30,9 @@ if ($migrationTableExists) {
|
||||
}
|
||||
|
||||
$allMigrations = glob('migrations/*.php');
|
||||
if (count($allMigrations) == 0) {
|
||||
$allMigrations = glob('../../migrations/*.php');
|
||||
}
|
||||
$requiredMigrations = array_diff($allMigrations, $completedMigrations);
|
||||
|
||||
if (count($requiredMigrations) === 0) {
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
) {
|
||||
$response = [
|
||||
"success" => false,
|
||||
"errorMessage" => "Please fill all fields"
|
||||
"errorMessage" => "Please fill all mandatory fields"
|
||||
];
|
||||
echo json_encode($response);
|
||||
} else {
|
||||
@ -25,6 +25,7 @@
|
||||
$smtpPort = $data["smtpport"];
|
||||
$smtpUsername = $data["smtpusername"];
|
||||
$smtpPassword = $data["smtppassword"];
|
||||
$fromEmail = $data["fromemail"];
|
||||
|
||||
$query = "SELECT COUNT(*) FROM notifications";
|
||||
$result = $db->querySingle($query);
|
||||
@ -37,12 +38,12 @@
|
||||
echo json_encode($response);
|
||||
} else {
|
||||
if ($result == 0) {
|
||||
$query = "INSERT INTO notifications (enabled, days, smtp_address, smtp_port, smtp_username, smtp_password)
|
||||
VALUES (:enabled, :days, :smtpAddress, :smtpPort, :smtpUsername, :smtpPassword)";
|
||||
$query = "INSERT INTO notifications (enabled, days, smtp_address, smtp_port, smtp_username, smtp_password, from_email)
|
||||
VALUES (:enabled, :days, :smtpAddress, :smtpPort, :smtpUsername, :smtpPassword, :fromEmail)";
|
||||
} else {
|
||||
$query = "UPDATE notifications
|
||||
SET enabled = :enabled, days = :days, smtp_address = :smtpAddress, smtp_port = :smtpPort,
|
||||
smtp_username = :smtpUsername, smtp_password = :smtpPassword";
|
||||
smtp_username = :smtpUsername, smtp_password = :smtpPassword, from_email = :fromEmail";
|
||||
}
|
||||
|
||||
$stmt = $db->prepare($query);
|
||||
@ -52,6 +53,7 @@
|
||||
$stmt->bindValue(':smtpPort', $smtpPort, SQLITE3_INTEGER);
|
||||
$stmt->bindValue(':smtpUsername', $smtpUsername, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':smtpPassword', $smtpPassword, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':fromEmail', $fromEmail, SQLITE3_TEXT);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
$response = [
|
||||
|
||||
@ -31,6 +31,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
$smtpPort = $data["smtpport"];
|
||||
$smtpUsername = $data["smtpusername"];
|
||||
$smtpPassword = $data["smtppassword"];
|
||||
$fromEmail = $data["fromEmail"] ?? "wallos@wallosapp.com";
|
||||
|
||||
$mail = new PHPMailer(true);
|
||||
$mail->isSMTP();
|
||||
@ -47,7 +48,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
$email = $user['email'];
|
||||
$name = $user['username'];
|
||||
|
||||
$mail->setFrom('wallos@wallosapp.com', 'Wallos App');
|
||||
$mail->setFrom($fromEmail, 'Wallos App');
|
||||
$mail->addAddress($email, $name);
|
||||
|
||||
$mail->Subject = 'Wallos Notification';
|
||||
|
||||
10
migrations/000003.php
Normal file
10
migrations/000003.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
// This migration adds a "from_email" column to the notifications table.
|
||||
|
||||
/** @noinspection PhpUndefinedVariableInspection */
|
||||
$columnQuery = $db->query("SELECT * FROM pragma_table_info('notifications') where name='from_email'");
|
||||
$columnRequired = $columnQuery->fetchArray(SQLITE3_ASSOC) === false;
|
||||
|
||||
if ($columnRequired) {
|
||||
$db->exec('ALTER TABLE notifications ADD COLUMN from_email VARCHAR(255);');
|
||||
}
|
||||
@ -507,6 +507,7 @@ function saveNotificationsButton() {
|
||||
const smtpPort = document.getElementById("smtpport").value;
|
||||
const smtpUsername = document.getElementById("smtpusername").value;
|
||||
const smtpPassword = document.getElementById("smtppassword").value;
|
||||
const fromEmail = document.getElementById("fromemail").value;
|
||||
|
||||
const data = {
|
||||
enabled: enabled,
|
||||
@ -514,7 +515,8 @@ function saveNotificationsButton() {
|
||||
smtpaddress: smtpAddress,
|
||||
smtpport: smtpPort,
|
||||
smtpusername: smtpUsername,
|
||||
smtppassword: smtpPassword
|
||||
smtppassword: smtpPassword,
|
||||
fromemail: fromEmail
|
||||
};
|
||||
|
||||
fetch('/endpoints/notifications/save.php', {
|
||||
@ -547,12 +549,14 @@ function testNotificationButton() {
|
||||
const smtpPort = document.getElementById("smtpport").value;
|
||||
const smtpUsername = document.getElementById("smtpusername").value;
|
||||
const smtpPassword = document.getElementById("smtppassword").value;
|
||||
const fromEmail = document.getElementById("fromemail").value;
|
||||
|
||||
const data = {
|
||||
smtpaddress: smtpAddress,
|
||||
smtpport: smtpPort,
|
||||
smtpusername: smtpUsername,
|
||||
smtppassword: smtpPassword
|
||||
smtppassword: smtpPassword,
|
||||
fromemail: fromEmail
|
||||
};
|
||||
|
||||
fetch('/endpoints/notifications/sendtestmail.php', {
|
||||
|
||||
@ -151,6 +151,7 @@
|
||||
$notifications['smtp_port'] = "";
|
||||
$notifications['smtp_username'] = "";
|
||||
$notifications['smtp_password'] = "";
|
||||
$notifications['from_email'] = "";
|
||||
}
|
||||
|
||||
?>
|
||||
@ -190,6 +191,9 @@
|
||||
<div class="form-group-inline">
|
||||
<input type="password" name="smtppassword" id="smtppassword" placeholder="SMTP Password" value="<?= $notifications['smtp_password'] ?>" />
|
||||
</div>
|
||||
<div class="form-group-inline">
|
||||
<input type="text" name="fromemail" id="fromemail" placeholder="From email (Optional)" value="<?= $notifications['from_email'] || "" ?>" />
|
||||
</div>
|
||||
<div class="settings-notes">
|
||||
<p>
|
||||
<i class="fa-solid fa-circle-info"></i> SMTP Password is transmitted and stored in plaintext.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user