I am having an html email template which uses certain merge fields from a custom object. Now I am using following apex code to send certain emails to users.
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTargetObjectId(t.OwnerId);
mail.setTemplateId(et.Id);
mail.setWhatId(t.Id);
mail.SaveAsActivity = false;
Messaging.sendEmail(new Messaging.singleemailMessage[] {mail});
Code is saved without error but when I run it it says "can't use whatId when sending email to users". Can anyone explain me how to overcome this error? When I use a visualforce template then same code works fine.