Magento Sending Custom Email

01 / Apr / 2013 by amatya 3 comments

By default magento sends emails on its certain events like customer registration, order creation etc. Also you can customize or change these email templates from admin > System > Transaction Email. What if you want add your own custom email template or if you want to add email feature in your custom module. This blog helps you in achieving this. Following are steps :

First of all create your email template test.html under following directory.

app\locale\en_US\template\email. Where en_US is your default language pack. You can replace it with your own.

[php]
<!–@subject Custom Email for {{var customVariable}} @–>
<!–@vars
{"store url=\"\"":"Store Url",
"var logo_url":"Email Logo Image Url",
"var logo_alt":"Email Logo Image Alt",
}
@–>
<!–@styles
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;">
Hello {{var custName}}<br>
Thank you. Your logo path is {{var logo_url}}
</div>
</body>
[/php]

<!–@subject : In this tag you can define subject line of your email.
<!–@vars : In vars section you can define your custom variable.
<!–@styles : In this tag section you can add custom style for your email template.
{{var custName}} : By using {{var custName}} you can add your custom variable in your email template.

Now add following code in your module’s config.xml file’s global node.

[php]
<template>
<email>
<test_email_template">
<label>Test Email</label>
<file>test.html</file>
<type>html</type>
</test_email_template>
</email>
</template>
[/php]

Now clear magento cache and go to admin > Transactional Email > Add New Template. From here you can load your cuatom email template

Add the following code in your controller’s action from where you want to send your email.

[php]
<?php
$templateId = 25 //your email template id;
$sender = Array(‘name’ => ‘Sender’s Name’,
’email’ => ‘test@test.com’);
//recepient
$email = ‘abc@test.com’;
$emaiName = ‘Sender’s Name’;
$vars = Array();
$vars = Array(‘customVariable’=>$yourCustomVarialbe,
);*/
$storeId = Mage::app()->getStore()->getId();
$translate = Mage::getSingleton(‘core/translate’);
Mage::getModel(‘core/email_template’)
->sendTransactional($templateId, $sender, $email, $emailName, $vars, $storeId);
$translate->setTranslateInline(true);
?>
[/php]

That’s it. Hope this will help you 🙂


Regards,
Amatya Trivedi
amatya@intelligrape.com

FOUND THIS USEFUL? SHARE IT

comments (3)

  1. trekking company nepal himalayatrekservices

    I enjoy what you guys are usually up too. This sort of clever work and reporting!
    Keep up the excellent works guys I’ve added you guys to my own blogroll.

    Reply
  2. Blogger Banua

    Thanks a lot for sharing this with all of us you really recognise what you are speaking about! Bookmarked. Please additionally consult with my web site =). We could have a hyperlink exchange agreement among us

    Reply

Leave a Reply

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