Dynamic SQL To Send HTML Email
Currently you have:

from 
(
   'Select * from #info Where name = ''' +@name + ''' '
) as d


This isn't valid, because you can't say FROM ('some query'), that's like saying FROM ('something that is not a query') because it is just a string. Try:

from
(
  Select * from #info Where name = @name
) as d


...in other words, why all the string wrapping? I did not parse the code, so there may be other problems, too. But that's the immediate one.