From: LeonardoBizzoni Date: Sun, 3 Jul 2022 08:36:16 +0000 (+0200) Subject: Fixed mail spam X-Git-Url: http://git.leonardobizzoni.com/?a=commitdiff_plain;h=c55f3ae58dcc0fd232182ae01c3a7afe584ff37f;p=highschool-graduation-project Fixed mail spam --- diff --git a/www/Migrations/m_1656833406_addedNotificationSentToFavorite.php b/www/Migrations/m_1656833406_addedNotificationSentToFavorite.php new file mode 100644 index 0000000..6f90516 --- /dev/null +++ b/www/Migrations/m_1656833406_addedNotificationSentToFavorite.php @@ -0,0 +1,21 @@ +db; + $sql = "ALTER TABLE vtubers ADD COLUMN sent BOOL default 0;"; + $db->pdo->exec($sql); + } + + public function down() + { + $db = Application::$app->db; + $sql = "ALTER TABLE vtubers DROP COLUMN sent;"; + $db->pdo->exec($sql); + } +} +?> diff --git a/www/mailer.php b/www/mailer.php index 8a20ff2..184c9c6 100644 --- a/www/mailer.php +++ b/www/mailer.php @@ -22,39 +22,44 @@ $config = [ $app = new Application(__DIR__, $config); -$stmt = $app->db->pdo->prepare(" -select email, vtubers.username, vtubers.id, notify +while (true) { + $stmt = $app->db->pdo->prepare(" +select email, vtubers.username, vtubers.id, notify, sent from users, vtubers, favoriteVtuber where _vtuberID=vtubers.id and _userID=users.id +and sent=0 and notify=1"); -$stmt->execute(); -$data = $stmt->fetchAll(); + $stmt->execute(); + $data = $stmt->fetchAll(); + foreach ($data as $row) { + // var_dump($row); + $mail = new PHPMailer; + $mail->IsSMTP(); // telling the class to use SMTP + $mail->SMTPAuth = true; + $mail->SMTPSecure = "ssl"; + $mail->Host = "smtp.gmail.com"; + $mail->Port = "465"; -foreach ($data as $row) { - // var_dump($row); - $mail = new PHPMailer; - $mail->IsSMTP(); // telling the class to use SMTP - $mail->SMTPAuth = true; - $mail->SMTPSecure = "ssl"; - $mail->Host = "smtp.gmail.com"; - $mail->Port = "465"; + $mail->Username = Application::$app->config["mail"]["username"]; + $mail->Password = Application::$app->config["mail"]["pass"]; - $mail->Username = Application::$app->config["mail"]["username"]; - $mail->Password = Application::$app->config["mail"]["pass"]; + $mail->SetFrom($mail->Username); - $mail->SetFrom($mail->Username); + $mail->Subject = $row["username"] . " is live!"; + $mail->Body = " "; - $mail->Subject = $row["username"] . " is live!"; - $mail->Body = " "; + $mail->AddAddress($row["email"]); - $mail->AddAddress($row["email"]); + if (!$mail->Send()) { + echo "Mailer Error: " . $mail->ErrorInfo . "\n"; + } else { + echo "Message sent!\n"; + $stmt = $app->db->pdo->prepare("update vtubers set sent=1 where id=".$row["id"]); - if (!$mail->Send()) { - echo "Mailer Error: " . $mail->ErrorInfo . "\n"; - } else { - echo "Message sent!\n"; + $stmt->execute(); + } } } diff --git a/www/vtuberIsLive.php b/www/vtuberIsLive.php index 54e20f2..e9c123e 100644 --- a/www/vtuberIsLive.php +++ b/www/vtuberIsLive.php @@ -76,7 +76,7 @@ while (true) { $tag = $result->item($i)->getAttribute("href"); if (str_contains($tag, "https://www.youtube.com/watch?v=")) { echo "{$vtuber["username"]} - $tag\n"; - $stmt = $app->db->pdo->prepare("update vtubers set live='$tag' where id=" . $vtuber["id"]); + $stmt = $app->db->pdo->prepare("update vtubers set live='$tag', sent=0 where live=NULL and id=" . $vtuber["id"]); $stmt->execute(); $isLive = true; }