One of the reason for getting formating error is if the output device is not available in SU01. In my case, the email was generating correctly but the PDF attachment was missing. Call the Smartform FM was giving me formatting error.
Hope it helps someone.