How to use custom email template while sending mail in magento

How to use custom email template while sending mail in magento

July 31, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to use custom email template while sending mail in magento

Customizing Email Templates in Magento: A Comprehensive Guide

Are you new to Magento and struggling with creating custom email templates? You’re not alone! In this guide, I’ll walk you through the process of building your own customizable email templates from scratch.

Understanding the Problem

You’ve created a new module named emailtemplate, complete with a database table and both PHP and PHTML files. While you can view your template UI, integrating it into the email sending process isn’t straightforward.

You’ve tried using Magento’s <block type> to no avail, and even implemented an observer without success. The question is: how do you effectively use these custom templates for various types of email formats while allowing admin users to edit them?

The Approach

To solve this, we’ll need to dive into Magento’s core functionality and make some strategic modifications.

Step 1: Create Your Template Files

Navigate to the app/design/frontend/ directory in your Magento installation. Here, you’ll find folders for each theme installed on your site.

Create a new folder named emailtemplate under one of these themes (e.g., inside /package/theme).

Inside this new folder, create another folder called templates. Within templates, make two more folders: html and text.

Step 2: Design Your Custom Templates

In the text folder, create a file with any name you like (for example, custom_email.txt). This is where your plain text email content will go.

Similarly, in the html folder, create another file (custom_email.html) for your HTML-formatted email content.

Design both templates according to your needs. Remember that Magento supports both plain text and HTML emails, so you’ll need to provide content for each format.

Step 3: Configure Your Email Templates

Next, open the app/code/core/Mage/config.xml file in a text editor. Look for the <global> tag near the beginning of the file.

Add an entry for your custom template:

<email_templates>
    <custom_email translate="label">
        <label>Custom Email</label>
        <template>custom_email</template>
        <type plaintext></type>
        <type html></type>
    </custom_email>
</email_templates>

Replace custom_email with the name you’d like to give your template.

Step 4: Update Your Email Sending Code

Now, wherever in your Magento installation you’re sending an email (for example, in a module), you can reference this new template. Here’s a simple example:

$templateId = 'custom_email';
$sender = array('name' => 'Admin User', 'email' => 'admin@example.com');
$receiver = array('name' => 'Customer Name', 'email' => 'customer@example.com');

Mage::getModel('core/email_template')->sendTransactional(
    $templateId,
    $sender,
    $receiver['email'],
    implode(',', $receiver),
    array(
        'var1'  => 'Value 1',
        'var2'   => 'Value 2'
    )
);

In this example, the custom_email template will be used to send a transactional email.

Conclusion

Creating and implementing custom email templates in Magento requires a deep understanding of the platform’s structure and core functionality. By following this guide, you can now:

  1. Design your own email templates.
  2. Configure them within the Magento system.
  3. Use them seamlessly in your sending code.

Remember that Magento is an extensive platform with many possibilities for customization. If you need further assistance or want to explore more advanced features like dynamic content insertion and image optimization, feel free to contact us at Laravel Company.

Happy coding!

Database Extensions Themes Admin

Our network