Even if I said something similar in the comments here it is as an answer, with some additional info.
When creating a module with a custom email template, the template is not supposed to appear in the custom template list. That list is only for the records in the table core_email_template
. After installing the module the template should appear in the dropdown list when adding a new template to the database.
If this still does not fit your needs you can add an insert
statement in the module install script that will add the same content to the template table.
INSERT INTO `{$this->getTable('core/email_template')}` SET
`template_code` = 'some_code_here',
`template_text` = 'YOUR TEMPLATE CONTENT HERE',
`template_styles` = 'custom template styles if any. if not leave null',
`template_subject` = 'Subject here',
`template_sender_name` = null,
`template_sender_email` = null,
`orig_template_code` = 'mycompany_mymodule_general_email_template',
`orig_template_variables` = 'custom vars if any in JSON format'
orig_template_code
should be the same as the tag name in your config.xml
file
More or less a few arrays to setup, I would suggest tacking onto an observer event (or a core rewrite, in which case you'll find the send function for customer registrations in the mage core customer folder!) to send your custom script out (there's a list of the observers available if you google!):
Declare the sender as an array:
$sender = Array('name' => 'You',
'email' => 'you@domain.com');
The recipient address, just literally needs to be a string, similarly to the mail subject.
$email = 'customer@customer.com';
Set your template id:
$templateId = 40;
And finally declare your custom variables to be sent along to the template:
$vars = Array('nameOfCustomer' => $customerName,
'shippingDetails' => $shipping,
'storeName' => $store_name,
'storeURL' => $store_url,
'orderId' => $orderId);
Followed up with the send function, i tend to just leave the $name as a null var:
$storeId = Mage::app()->getStore()->getId();
$translate = Mage::getSingleton('core/translate');
Mage::getModel('core/email_template')
->setTemplateSubject($mailSubject)
->sendTransactional($templateId, $sender, $email, $name, $vars, $storeId);
Then in your template call the var as literal for example:
{{var storeName}}
Best Answer
In a situation like this it's generally useful to follow the logic of the corresponding admin user action, which posts to
Mage_Adminhtml_System_Email_TemplateController::saveAction()
:You can essentially do the same in your setup script, with the obvious difference being that instead of POST params accessed via a request object you are creating your own array directly in the code.