Skip to main content

Magento Send Custom Email

If you are a webmaster or web developer you are already aware that magento sends email on certain even. For example: on order creation, invoice generation, on customer registration. You can manage these email template using System->Transaction Email section  well. Now  if you are web developer you may face some moment when you need to send email from magento at some custom event or inbuilt event in magento. One way of sending email is just to use PHP script and mailer function. Other way of sending custom email from magento is like creating of your own email template and sending those email template. In my post “Magento Send Custom Email” I will explain how to send email using Custom Email template programmatically . Sending custom email from magento involves two steps, first is creation of your custom email template and other is to write script.

Magento Send Custom Email – Template Creation

First of all question is why you need to create custom email ? It has tow reason. First your webmaster can modify content or design of your email. Other you can add some variable in custom email which your webmaster can use in any place in the template, so it will make your webmaster easy to play with email. Template creation involve 2 work. First create .html format of your email and second is add your email information in your module config.xml. Let us create a custom email template. Create your custom email and place it in folder \app\locale\en_US\template\email. Where en_US is your

<[email protected] custom Email for {{var customVar}} @-->
<[email protected]
{"store url=\"\"":"Store Url",
"var logo_url":"Email Logo Image Url",
"var logo_alt":"Email Logo Image Alt",
<[email protected]
body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; }
<body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
<div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
Hi {{var custName}}<br>
Thank you for sending email. Your logo path is {{var logo_url}}

Tag Description of the code:

  • <!–@subject : This tag define the subject line of your email
  • <!–@vars : In vars section you can define your own constant variable for your email template
  • <!–@styles : In style section you can add custom style for your email template.
  • {{var custName}} : By using {{var customevariable}} you can insert custom variable in your email template. You can replace these custom variable by passing array in email send function. I will explain this process latter in this article.

Code/Script and Config.xml setting for Email Sending

Add following code in your module config.xml under global tag.

<label>Test Email Template</label>

After adding above code in config.xml file clear cache of magento.
Now when you will go to System ->Transactional Emails -> Add New Template can load your template. You can see your “Test Email” Template in the Template list and please select default language and click on load button. Below is the screenshot.

Magento Send Custom Email
Add Email template in magento

Save your template and

Now Add following code from where you want to send email:

In My case I will use it in controller:

$templateId = 10;
$sender = Array('name' => 'Ankur',
'email' => '[email protected]');
$email = '[email protected]';
$emaiName = 'Ankur';
$vars = Array();
$vars = Array('customVar'=>$yourvarialbe,
$storeId = Mage::app()->getStore()->getId();
$translate = Mage::getSingleton('core/translate');
->sendTransactional($templateId, $sender, $email, $emailName, $vars, $storeId);

Now your email will be sent out.

Here you can download my email sending module.

If you like my article please write your feedback and vote us.


Support Me by Sharing This Article

Ankur Kumar Singh

I am a PHP programmer having some knowledge about Linux. I am always interested in web development and knowledge sharing. I am full time tech evangelist part time human being. :-)

Leave a comment/Ask Question

8 thoughts on “Magento Send Custom Email

  1. i have download your module and put it in codepool “local” but there is no config.xml file to declare module which i have to placed in app/etc/modules/.

    Please tell me how can i use it.

  2. i want to set subject is ‘ Firstname Name, réinitialisez votre mot de passe CKT ‘.But when i am set the email will not send. i am working on forget password email . i have done from both (admin and from transactional emails) . kindly help