Yes, it is just a code ordering issue.
You send the email before you store the order in the database, and generate the email contents from the most recently inserted order, which would be the one before the current.
The solution is to move the email code on the confirm page below the database inserts on the confirm.php page.
So move lines 476-562 below the last database insert that currently ends on line 737