CommercePeer Brand Logo


Programmatically: Magento 2 Product Entity

Programmatically: How to customize Magento's email templates

Step 1: Create a new folder

Create a new folder in the app/code/local directory with a unique name, for example, MyCompany_CustomEmail.

Step 2: Create a new module

Inside the MyCompany_CustomEmail folder, create a file called module.xml with the following code:


	
	
    
        
         true
         local
        
    
	

	

Step 3: Create a new email template

Create a new file called email_templates.xml in the app/code/local/MyCompany/CustomEmail/etc directory with the following code:


	
	
    
        
        My Custom Email Subject
    
	

	

Step 4: Create the email template file

Create a new file called my_email_template.phtml in the app/code/local/MyCompany/CustomEmail/email directory with the following code:


	defined('ABSPATH') or exit;

	$customerName = Mage::getSingleton('customer/session')->getCustomer()->getName();
	$mailTemplate = Mage::getModel('core/email_template')->loadDefault('my_email_template');
	$mailTemplate->setTemplateParams(array('customer_name' => $customerName));
	$mailTemplate->send($toEmail, $toName);

	

Step 5: Enable the module

Go to System > Configuration > Advanced > Advanced > Disable Modules Output and set MyCompany_CustomEmail to Yes.

Step 6: Test the email

Go to System > Configuration > Sales > Sales Emails > Order > New Order Email and select your custom email template from the dropdown list.

This will send an email to the customer with the custom subject and body defined in your custom email template.

Alternatively, you can also use Magento's built-in email template placeholder syntax to customize the email template without creating a new module. You can use placeholders like {customer.name} to insert customer information into the email template.

Here's an example of using placeholders:


	
	defined('ABSPATH') or exit;

	$mailTemplate = Mage::getModel('core/email_template')->loadDefault('order/new');
	$mailTemplate->setTemplateParams(array(
    '{customer.name}' => Mage::getSingleton('customer/session')->getCustomer()->getName()
	));
	$mailTemplate->send($toEmail, $toName);
	
	

LET’S WORK TOGETHER

We love working with Small Businesses, Retailers, Manufacturers. Our team is here to Help.

→ Schedule Free Consultant Now
Copyright © 2024 CommercePeer. All Rights Reserved.