It's worth noting that if you make use of the XenForo addon system (and corrosponding MVC architecture) it does a lot of the leg work for you. It can take time to learn but it's worth it.
That said, something like this should get you started:
Saving that PHP script somewhere web accessible and using it as your preview URL should put the content of $data['templateHtml'] in your tooltip. Obviously this is just a simple example.