发送您的自定义电子邮件模板的示例:
public function sendCustomMail()
{
$emailTemplate = Mage::getModel('core/email_template');
$emailTemplate->loadDefault('custom_template_name');
$emailTemplate->setTemplateSubject('my subject here');
// Load from magento config..
$email = Mage::getStoreConfig('trans_email/ident_general/email');
$name = Mage::getStoreConfig('trans_email/ident_general/name');
$emailTemplate->setSenderName($name );
$emailTemplate->setSenderEmail($email);
// Add some custom variables here to pass into the template.
$emailTemplateVariables['username'] = ' something';
$emailTemplateVariables['store_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
$emailTemplate->send('customer@domain.com', 'name...', $emailTemplateVariables);
}
您还需要将自定义模板添加到模块配置中
配置文件
<config>
...
<global>
...
<template>
<email>
<custom_template_name module="Namespace_Module">
<label>Custom Template</label>
<file>mycustomtemplate.html</file>
<type>html</type>
</custom_template_name>
</email>
</template>
</global>
</config>
然后,您可以与其他人一起添加您的自定义电子邮件模板
/app/locale/en_US/template/email/mycustomtemplate.html
<h1>Dear {{var username}}</h1>
<p>bla bla </p>
<div>{{var storename}} ({{var store_url}})</div>