Magento custom emails

Magento custom emails

Ever wanted to “just send the email” using the built in email features in Magento? Ever hit the wall trying to do something with Magento? OK, I know the answer to the other one, just had to ask :). Anyhow, sending the emails with Magento turned out to be a process of “just” a few hours of tracing Magento code.

I cant wait for smart comments like, “few hours, huh its so easy…”. Yea, thats the beauty of Magento… few hours of bashing your head against the wall while you are sipping the 4th cup of coffee until the solution hits you. Interesting do, just when you get the hang of it, Magento gets you this “have you tried this” attitude :).

What am I talking about? Scenario: I want to create email template named activecodeline_custom_email1.html, I want to pass few variables to it during runtime, I want to send emails programmaticaly. I dont want to create 56 lines of xml file just to call one template.

Here is how.

 * Loads the html file named 'custom_email_template1.html' from
 * app/locale/en_US/template/email/activecodeline_custom_email1.html
$emailTemplate  = Mage::getModel('core/email_template')
//Create an array of variables to assign to template
$emailTemplateVariables = array();
$emailTemplateVariables['myvar1'] = 'Branko';
$emailTemplateVariables['myvar2'] = 'Ajzele';
$emailTemplateVariables['myvar3'] = 'ActiveCodeline';
 * The best part :)
 * Opens the activecodeline_custom_email1.html, throws in the variable array
 * and returns the 'parsed' content that you can use as body of email
$processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
 * Or you can send the email directly,
 * note getProcessedTemplate is called inside send()
$emailTemplate->send('','John Doe', $emailTemplateVariables);

And here we go again, nothing without xml files 🙂 -In order for above piece of code to work, you need to add an entry to your config.xml file like shown below.

				<label>ActiveCodeline custom email module</label>

And lets not forget the email template itself, app/locale/en_US/template/email/activecodeline_custom_email1.html.

<!--@subject ActiveCodeline custom email module @-->

ActiveCodeline custom email example by Branko Ajzele

Hi there {{var myvar1}} {{var myvar2}} from {{var myvar3}}. This is just some example template to test custom email module.

Hope this was helpful. In case you need some help regarding Magento Development, we would be happy to help. Our team of experts would love to review your code and offer insights on improving your store. Our Magento Technical Audit is a great way to start – feel free to contact us!

You made it all the way down here so you must have enjoyed this post! You may also like:

Enabling Multi-part MIME Emails in Magento Tomislav Nikcevski
Tomislav Nikcevski, | 3

Enabling Multi-part MIME Emails in Magento

Extending “Contact us” functionality in Magento Ivan Bernatovic
Ivan Bernatovic, | 8

Extending “Contact us” functionality in Magento

Magento’s transactional eMails do-s and don’t-s Adrian Bece
Adrian Bece, | 10

Magento’s transactional eMails do-s and don’t-s


  1. Hey guys, I followed the instructions, added a custom module to my magento. Everything seems to work. *except* I get a Blank E-Mail. As If the Template was not found.
    Any suggestions?

    1. Yes, check which locale is set, if the html file was added to a different directory than set up in your current locale, you will get an empty e-mail.

  2. i’m working in magento, i have one problem that i’m not able to send email to all customers.what can i do for send email to all customers. i done used all versions.

  3. Hello There,
    I could not properly get it. Sorry i am new to this and Magento.
    I want to change the output of the {{var items}} variable.
    Basically i want to disable the add to cart option on the the emails, for shared wishlist, share with friend (all mails going out).
    Any direction on how to achive that.
    Thanks in advance for your help.
    Vicky T

    1. Make sure you loading “custom_email_template1” and not the “activecodeline_custom_email1”.

  4. Great tutorial!
    But you need to have installed ‘sendmail’ package if you are using Ubuntu and have it enabled.
    Do this by the following commands:
    $ sudo apt-get update
    $ sudo apt-get install sendmail


  5. Being new in Magento one of my senior suggest me to follow Inchoo & its relay great. I can solve Above 70% problem from here(Like: magento custom template).

  6. try this code it works..

    $emailTemplate = Mage::getModel(‘core/email_template’)->loadDefault(‘custom_email_template1′);

    //Getting the Store E-Mail Sender Name.
    $senderName = ‘billa’;

    //Getting the Store General E-Mail.
    $senderEmail = ‘’;

    //Variables for Confirmation Mail.
    $emailTemplateVariables = array();
    $emailTemplateVariables[‘myvar1′] = ‘Branko’;
    $emailTemplateVariables[‘myvar2′] = ‘Ajzele’;
    $emailTemplateVariables[‘myvar3′] = ‘ActiveCodeline’;

    //Appending the Custom Variables to Template.
    $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);

    //Sending E-Mail to Customers.
    $mail = Mage::getModel(‘core/email’)
    ->setSubject(‘Subject :’)
    //Confimation E-Mail Send
    catch(Exception $error)
    return false;

    1. Thanks, I think you should use
      $mail = $emailTemplate()->getMail();
      instead of
      $mail = Mage::getModel(‘core/email’);

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.