Since you know each php set of code works why didn't you merge the two? Remember I take it you are a programmer since you didn't put this out as a for hire piece of work.
For example, in your database.php code, at line 27 you have your database updated so at that point you insert the relevant code (with changes to variable names if need be) from your email.php.
Remember I don't know folk's skill levels or expectations unless they call it out. But it appears you have all the code you need right now. You only need to create a new do-it-all both log to the database (you got that) then after line 27 in database.php perform the email steps from email.php.