PHP script to modify .forward files

Hi. I've been racking my brain on a project I've been working on for work, and hope someone here might be of assistance. Basically I'm trying to create dynamically generated .forward files for users/aliases on my email server. The intent is for these files to be generated automatically any time there is a personnel change at the company.

For example, I have a 'sales' email account setup that acts to forward any emails sent to it to all the actual staff emails listed in my mySQL database as part of the sales group. We have a web interface for modifying/assigning such groups to staff members, and this info is stored in the database.

What I'm trying to figure out is, once an assignment is made through this interface, how can I automatically update the .forward files through PHP telling the server to update the .forward files. It seems the only way to do this is to be running as root, but from what I gather, it's a security risk to gain root access in the PHP script itself. Ideally the script would just somehow signal root to update the .forward files for the appropriate email accounts. Rather than have a cron job create these .forward files at set intervals, I'd rather the changes be made instantaneously any time the .forward files need to be updated. Any ideas?

is there some reason why you want to implement this with PHP? Or you are open to other options?

May not be ideal but the whole web interface is written in PHP... i already have a PHP script that just generates the forwarding files from the database, and it works beautifully when you run it from root..b/c only root has the ability to modify all users .forward files.. but I need to figure out how to call this script whenever it needs to be called, from the web interface... i'm relatively inexperienced with linux so any feedback would be helpful.

The way I'm doing it now is way easier than the original approach of piping emails into a script and trying to manually modify the headers and then resend the mail..what a nightmare

What version of MySQL are you using? If it's 5.0 or higher, you should be able to use triggers and UDF to manipulate files. I haven't tried this myself but here's some info:

MySQL :: MySQL 5.0 Reference Manual :: 18.3 Using Triggers
MySQL :: MySQL 5.0 Reference Manual :: 21.2.2 Adding a New User-Defined Function

J.