Send emails using magento's email template Mechanism
Article category: PHP programming
Magento's Mage: GetModel ('Core/email_template ') model can be used for sending mail.
Step I.
Add code under the root tag <config> of ETC/config. xml of your module (which can be used by any module)
XML Code
<Default>
<{Qualified name 1}>
<{Qualified name n}>
<Enabled> 1 </enabled>
<Template> {email template tag name} </template>
</{Qualified name n}>
</Name restriction>
</Default>
<Global>
<Template>
<Email>
<{Email template label name} translate = "label" module = "{Module name}">
<Label> {any identity name} </label>
<File> {email template HTML file name} </File>
<Type> HTML </type>
</{Email template Tag Name>
</Email>
</Template>
</Global>
A) define the new email template tag and template file name under global/template/email. The template file name is similar to the CMS page and should be placed under the APP/locale/{current language}/template/email directory or subdirectory.
B). Default/lower limit name 1... limit name n references the email template defined under global
Limit name 1... limit name n indicates that a tag can be nested with one or more layers for distinguishing from Other Default labels.
For example:
XML Code
<Default>
<Customer_email>
<Services_request>
<Enabled> 1 </enabled>
<Template> customer_email_service_template </template>
</Services_request>
</Customer_email>
</Default>
<Global>
<Template>
<Email>
<Customer_email_service_template translate = "label" module = "sales">
<Label> Customer Services request </label>
<File> customer_services.html </File>
<Type> HTML </type>
</Customer_email_service_template>
</Email>
</Template>
</Global>
Step II.
Create customer_services.html and place it in the app/locale/{current language}/template/email directory (content omitted ).
Step III. Code call example
PHP code
/* @ Var $ translate mage_core_model_translate */
$ Translate = Mage: getsingleton ('Core/translate ');
$ Translate-> settranslateinline (false );
$ Storeid = Mage: APP ()-> getstore ()-> GETID ();
$ Template = Mage: getstoreconfig ('customer _ email/services_request/template', $ storeid );
$ Recipient = array (
'Name' => 'Baby ',
'Email '=> 'elon. guo@gmail.com'
);
$ Sender = array (
'Name' => 'koda guo ',
'Email '=> 'oda. guo@gmail.com'
);
$ Mailtemplate = Mage: GetModel ('Core/email_template ');
$ Mailtemplate-> setdesignconfig (Array ('area '=> 'frontend', 'store' => $ storeid ))
-> Sendtransactional (
$ Template,
$ Sender,
$ Recipient ['email '],
$ Recipient ['name'],
Array (// parameters to email
'Param1' => 'abc ',
'Param2' => 'def ',
'Param3' => 'ghi'
)
);
$ Translate-> settranslateinline (true );
Using the magento template mechanism, once a new template is defined, the template can be customized at system> transactional mail in the background to facilitate maintenance.