Send report to email (HTML)
Your insert to #temp and #temp2 works perfectly fine.

I believe you are getting the below error.


  Msg 156, Level 15, State 1, Line 70 Incorrect syntax near the keyword
  'AS'.


This error is due to the explicit aliasing on the below part of the code.

td = T1.avg_fragmentation_percent AS avg_fragmentation_percent_pre_change, '',
td = T2.avg_fragmentation_percent AS avg_fragmentation_percent_post_change


since you have already aliased it as 'td'. it will become like this

td = T1.avg_fragmentation_percent , '',
td = T2.avg_fragmentation_percent 


Remove the explicit aliasing using AS and run the code and see it works. I did test run 
and it worked.