you could have avoided the whole riggamora of that thing by just stating:
$to = "$firstname.lastname@example.org
here's why it didn't work.
$email = '$email@example.com
This single tick blocks transformation of variables to strings in output.
Using double quotes " " will transform variables to strings in output.
$to = $email;
An un-needed, unnecessary step. creating two variables with the exact same information is ... you get the idea.