Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Jun 2017
Posts: 15
Newbie
Newbie
Offline
Joined: Jun 2017
Posts: 15
Users (including me) sometimes get 14–21 birthday notices. The root cause is likely no uniqueness check or sent flag—emails can re-trigger if cache rebuilds or queries return the same user multiple times.
Simple fix idea:
Add two columns to USER_PROFILE:
SQL
Code
ALTER TABLE {table_prefix}USER_PROFILE 
ADD COLUMN BIRTHDAY_EMAIL_SENT TINYINT(1) DEFAULT 0,
ADD COLUMN BIRTHDAY_EMAIL_SENT_YEAR INT UNSIGNED DEFAULT 0;

In the birthday email sending logic (wherever it mails users):
SQL
Code
UPDATE {table_prefix}USER_PROFILE 
SET BIRTHDAY_EMAIL_SENT = 1, BIRTHDAY_EMAIL_SENT_YEAR = YEAR(CURDATE())
WHERE USER_ID = ?;

In the birthdays.php query, add condition:
SQL
Code
AND (t2.BIRTHDAY_EMAIL_SENT = 0 
     OR t2.BIRTHDAY_EMAIL_SENT_YEAR != YEAR(CURDATE()))
Logic:

Sent=0, year ≠ current → send (new year)
Sent=1, year ≠ current → send (reset for new year)
Sent=0, year = current → send (first time this year)
Sent=1, year = current → skip (already sent)

This ensures one email per user per year. No duplicate sends, no lost emails.
Happy to test or provide diffs if helpful. Just a reliability tweak.


The Stovebolt Geek
https://www.stovebolt.com/ubbthreads/ubbthreads.php

Server Information
UBB.threads Version 8.0.0
Release 20240826
Server OS Linux
Server Load 0.11
Web Server Apache/2.4.37
PHP Version 8.3.11
MYSQL Version 8.0.39
Database Size 1.94 GB
Sponsored Links
Joined: Jun 2017
Posts: 15
Newbie
Newbie
Offline
Joined: Jun 2017
Posts: 15
Multiple birthday emails fixed by adding this at the top of trigger_birthday_notifications() in libs/triggers.inc.php (right after globals):

Cause of multiples:
The forum index page calls the birthday function every time it loads. On a busy day many users (and bots) visit the index → the function runs many times → each run tries to send emails to everyone whose birthday is today.

Code
PHP// Skip if already sent today
$query = "SELECT CACHE_VALUE FROM {$config['TABLE_PREFIX']}CACHE WHERE CACHE_FIELD = 'birthdays'";
$sth = $dbh->do_query($query, __LINE__, __FILE__);
list($sent_today) = $dbh->fetch_array($sth) ?: [''];
if ($sent_today === $today) {
    return;
}

Why the fix stops duplicates:
The added check looks at the CACHE 'birthdays' value before doing anything.
If it already matches today’s date, the function stops immediately.
The first run of the day sends one email to each user who has a birthday today and then sets the CACHE value. All later runs see the updated value and skip the whole process.
This way every qualifying user gets exactly one email, and no duplicates are sent.

Backup your files first. Test with page reloads.
Kept "Send birthday email" disabled until patched, because until it's patched, multiple emails will be sent.


The Stovebolt Geek
https://www.stovebolt.com/ubbthreads/ubbthreads.php

Server Information
UBB.threads Version 8.0.0
Release 20240826
Server OS Linux
Server Load 0.11
Web Server Apache/2.4.37
PHP Version 8.3.11
MYSQL Version 8.0.39
Database Size 1.94 GB
Joined: Jun 2017
Posts: 15
Newbie
Newbie
Offline
Joined: Jun 2017
Posts: 15
This entire conversation should be superceded by Isaac's elegant fix: https://www.ubbcentral.com/forums/u...le-birthday-emails-being-sent#Post266939


The Stovebolt Geek
https://www.stovebolt.com/ubbthreads/ubbthreads.php

Server Information
UBB.threads Version 8.0.0
Release 20240826
Server OS Linux
Server Load 0.11
Web Server Apache/2.4.37
PHP Version 8.3.11
MYSQL Version 8.0.39
Database Size 1.94 GB
Joined: Jun 2017
Posts: 15
Newbie
Newbie
Offline
Joined: Jun 2017
Posts: 15
Problem:
Birthday emails were being sent multiple times per day due to a type mismatch and the lack of an immediate early exit, allowing re-processing even with a lock.

The following is log evidence from the admin log on our server of multiple birthday email batch runs. Each entry shows the time the process ran, who ran it, the number of emails sent, and the display names of the recipients. This is only a partial view. Some users have reported receiving as many as forty birthday emails. If you examine the lists of display names, you will see people being sent emails on multiple days as well. SaluteProducts, GucciVSbag1, 69 k20, lanebradford, GMC XLI, John Self, Wildman38, NCars, 1954trucker, Brittain, stylemaster47, mac_the_yankee, Brian Moore, Ian Ferguson, MoonDawg, JohnG 53, 1bigpig!, Bart, BenTolson, slotmandave, slick59, Fleetwoodfloyd, Hookalatch, Bobinpa, CaptKen47, noodlenose, sepp, tirediron
[Linked Image from stovebolt.com]
[Linked Image from stovebolt.com]
[Linked Image from stovebolt.com]

Note: the developer fixed a separate problem by ensuring that the value for birthday in {$config['TABLE_PREFIX']}CACHE was not erased when the cache was cleared. This was a necessary fix but did not completely resolve the issue

Solution:
  • Added early string exit if $sent === $today (lines 108-110) — prevents a re-run on same day.
  • Simplified lock claim query (lines 113-119) — removed redundant AND CACHE_VALUE = ? clause (original had unnecessary extra check; affected_rows suffices).
  • Added $sent_count tracking + optional debug log (lines 144, 153-154, 166-167) — counts emails and logs batch size.


Code Changes:

Early exit (added after globals - lines 104 & 105):

PHP
Code
// Quick exit if already done today
if ($sent === $today) {
    return;
}

Simplified lock claim (replaced original lines 115-120):

PHP
Code
$query = "
    UPDATE {$config['TABLE_PREFIX']}CACHE
    SET CACHE_VALUE = ?
    WHERE CACHE_FIELD = 'birthdays'
";
$dbh->do_placeholder_query($query, array("PENDING-$rightnow"), __LINE__, __FILE__);
Sent count + log (added in loop and after - added after line 165 - at the end of the function):

PHP
Code
  165     // Optional: log how many we sent (for debugging)
         if ($sent_count > 0) {
             admin_log("BIRTHDAY_BATCH", "Sent $sent_count birthday emails");
         }
This last one adds a line to the admin log that looks like this:
2026-01-02 18:00:37 UBB.threads (IP address) BIRTHDAY_BATCH Sent 27 birthday emails

Birthday emails should only be sent by UBB threads, not by user actions, and, if you incorporate this line, you should see one entry per day.


The Stovebolt Geek
https://www.stovebolt.com/ubbthreads/ubbthreads.php

Server Information
UBB.threads Version 8.0.0
Release 20240826
Server OS Linux
Server Load 0.11
Web Server Apache/2.4.37
PHP Version 8.3.11
MYSQL Version 8.0.39
Database Size 1.94 GB

Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Shock Hosting
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
Nettomo
Nettomo
Germany, Bremen
Posts: 417
Joined: November 2001
Forum Statistics
Forums63
Topics37,583
Posts293,955
Members13,825
Most Online151,614
Nov 14th, 2025
Today's Statistics
Currently Online 2455
Topics Created 0
Posts Made 0
Users Online 0
Birthdays 7
Top Posters
AllenAyres 21,080
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,834
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2026 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.1.0
(Snapshot build 20260108)