Line 166 on send_email.lua is:
subject = subject:gsub("${caller_id_name}", caller_id_name);
So, I would say, your subject variable is not getting populated. It may be that subject = row["template_subject"]; is not getting any value. So, check the query starting on line 123.
What is your...