Adding Custom Emails to Modules


I have 2 areas of questions on custom emails. I’m using PHPMailer in a trigger file already, but I want the system users to be able to modify email templates as needed. So PHPMailer is not the ideal solution if I want to use the templates. These will be used in a cron to give ongoing order status updates to customers, notification of new orders entering the system, internal status updates, etc.

1.) I’m looking for a list of existing codes for use in the email templates. The admin is specifically asking for a code, but does not provide a list. I see a small number of existing ones like “(SendingEmailOnAutoSubscription)” in the admin, but I have not come across a full list, or what best practices are for creating new ones. Should it correspond to the module name or can it be anything for our own reference?

2.) What hook or class do you call to to utilize/send a custom email template in a custom module?

I wound up using the function fetchAllEMailTemplate from core/class/html.formmail.class.php as a guide for grabbing custom messages.

I don’t think it matters what “code” name you use as long as you reference the right rowid or code depending on how you write your query.

The table is llx_c_email_templates assuming you are using the default MAIN_DB_PREFIX. Obviously this would work regardless of what your prefix is since it is set as a constant. $sql.= " FROM ".MAIN_DB_PREFIX.‘c_email_templates’

Once you have the custom email you need to translate the predefined constants. I haven’t gotten to this yet, but I believe it is the function make_substitutions in /core/lib/functions.lib.php, function setSubstitFromObject or something similar.

From there you just need to call your class/functions from the trigger file under /core/triggers like interface_99_all_MyTriggers.class.php. Don’t forget to use a number to set the priority!!

I hope this helps someone else trying to figure out how to do this.