populate_pending_emailsfunction copies entries from the
pending_emailstable into the
sent_emailstable and then deletes them from the
Modify the behavior of your script so that instead it only deletes
entries from the
pending_emailstable. When the trigger function is activated it will perform the insertion (of entries being deleted) into the
The result is that the logging of sent emails is handled by a trigger rather than embedded in the script.