Script to auto-email based on dates

Hi, I’m trying to figure a way of getting my job management system, which I’ve set up in PHP, to email some admin people when a payment is due on a project.

Basically I have a MySQL database table “Projects”. When a project gets added, it has fields that define staged payments on specific date: Payment1, Payment2, Payment3, Payment4, Payment5 and Payment6 (which are of type decimal- they hold currency values), and Payment1Date, Payment2Date, Payment3Date, Payment4Date, Payment5Date and Payment6Date (date fields which hold the date that that needs to be paid by)

Ideally I need a script of some sort to scan the projects on the system and trigger an email out to recipients, (a) when it’s 2 weeks before PaymentDate- this is to remind the admin people to invoice as the terms are 14 days, and (b) on the date itself, so that they can chase for payment. Even more ideally I’d like the system to check to see if the customer has made their payment before the 2nd email alert is sent, but that might be complicating things a bit.

Any idea if this can be done? I’m guessing it needs a script that automatically checks the dates continually, rather than a flat PHP file that will only run if prompted.