Send emails using magento's email template Mechanism

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.