Home » Magento31 May 2011

Magento: Send Transactional Email

In Magento, Transactional Email Templates can be created from System -> Transactional Emails. This article shows
how we can send transactional emails programmatically.

There are few necessary things for any transactional email in Magento. They are:-

Template ID = ID of your transactional email template
Sender Name
Sender Email
Recepient Name
Recepient Email
Store ID = Current user’s store ID
Vars = Variables to use in transactional email template

Add a new template from System -> Transactional Emails and then you will see the ID of your template. That is your
Template ID to be used in code below.

You can write Sender Name, Sender Email, Recepient Name, and Recepient Email manually or you can the name and email from Store Email
Addresses (System -> Configuration -> GENERAL -> Store Email Addresses).

Store Email Addresses

In the code below, Sender Name and Email is taken from Store Config and Recepient Name and Email is written manually.

Custom variables for transactional email templates can be used with curly brackets like:-
{{var myVariableName}}

New email template

Here is the full code to send transactional email in Magento:-

Hope this helps. Thanks.

Magento

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed
  • Vijay1982 Msc

    it is greate but html not support

  • Alok Kumar

    Here is my code & excuting  from my custom module save action (From admin), but it not sending email.

    php code: 

    $templateId = 5;
    $storeId = Mage::app()->getStore()->getId();
    $senderName = Mage::getStoreConfig(‘trans_email/ident_support/name’);
    $senderEmail = Mage::getStoreConfig(‘trans_email/ident_support/email’);
    $sender = array(‘name’ =>’Gaurav’,’email’=>’gaurav@sparxtechnologies.com’);
    $receipentName = ‘Alok’;
    $receipentEmail = ‘alok.kumar@sparxtechnologies.com’;
    $vars = array(‘customername’ =>’Gaurav’,’customeremail’=>’gaurav@sparxtechnologies.com’);
    $translate = Mage::getSingleton(‘core/translate’);
    Mage::getModel(‘core/email_template’)->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
    $translate->setTranslateInline(true);

    Template Id: 5  data:  

    Name: {{var customername}}
    E-mail: {{var customeremail}}

  • Alok Kumar

    Here is my code & excuting  from my custom module save action (From admin), but it not sending email.

    php code: 

    $templateId = 5;
    $storeId = Mage::app()->getStore()->getId();
    $senderName = Mage::getStoreConfig(‘trans_email/ident_support/name’);
    $senderEmail = Mage::getStoreConfig(‘trans_email/ident_support/email’);
    $sender = array(‘name’ =>’Gaurav’,’email’=>’gaurav@sparxtechnologies.com’);
    $receipentName = ‘Alok’;
    $receipentEmail = ‘alok.kumar@sparxtechnologies.com’;
    $vars = array(‘customername’ =>’Gaurav’,’customeremail’=>’gaurav@sparxtechnologies.com’);
    $translate = Mage::getSingleton(‘core/translate’);
    Mage::getModel(‘core/email_template’)->sendTransactional($templateId, $sender, $recepientEmail, $recepientName, $vars, $storeId);
    $translate->setTranslateInline(true);

    Template Id: 5  data:  

    Name: {{var customername}}
    E-mail: {{var customeremail}}

  • Alok Kumar

    My magento version is 1.5.1.0

  • Shafraz Mhmd

    it helped

  • Lphamvan

    great post, Thanks

  • Lphamvan

    How I can attach a file in email?

  • Bsegal26

    Hi Mukesh,

     I just wanted to let you know that I’ve been working with Magento for a few months now, and almost any time I have an issue, I find your blog which is super helpful.  Thank you for saving me hours of headaches.

  • jura

    how can i add bcc

  • daavem

    $store = Mage::app()->getStore()->getId();

    Should be:
    $storeId = Mage::app()->getStore()->getId();

  • Israel Guido

    Thanks, single example that actually worked

  • Adam Allen

    Hey,

    This there a way of sending out a single email to all of my customers? I already have the code for the email in the transactional email section of magento, i just do not know how to send it to all of my customers at once?

  • Giang Nghiem Truong

    Article is very good, thanks

  • Lohith

    This code is not working:( I have create a transactional email template and created a trans.php file and copied the code as you given and made modification with template ID, and name and email related things as i want But its not at all working… Any solution? I have added the code which i added to the file.

    Please let me know where i was missing

  • Ibad BTP

    My email is sending twice could you please help me? I am using Magento 1.13

  • Carmen Peters

    Hi
    I was previously using mandrill to send transactional emails, I would however like to use magento to send. Where will I input the code?