is the script associated with a user action like clicking a button or following a link, or is it supposed to just happen anytime mail hits the server?
if it's triggered by user action, then that should be pretty straightforward.
if not, then i think you'll have to make a script that'll do it, make it executable, and then run it as something that gets called automatically every day, or hour, or whatever. PHP won't do that, you'll have to set up somthing in inetd or something like that.
-john