{"id":10107,"date":"2013-04-01T14:13:15","date_gmt":"2013-04-01T08:43:15","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=10107"},"modified":"2013-04-01T14:13:15","modified_gmt":"2013-04-01T08:43:15","slug":"magento-sending-custom-email","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/magento-sending-custom-email\/","title":{"rendered":"Magento Sending Custom Email"},"content":{"rendered":"<p>\nBy 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 &gt; System &gt; 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 :\n<\/p>\n<p>\nFirst of all create your email template test.html under following directory.\n<\/p>\n<p>\napp\\locale\\en_US\\template\\email. Where en_US is your default language pack. You can replace it with your own.\n<\/p>\n<p>[php]<br \/>\n&lt;!&#8211;@subject Custom Email for {{var customVariable}} @&#8211;&gt;<br \/>\n&lt;!&#8211;@vars<br \/>\n{&quot;store url=\\&quot;\\&quot;&quot;:&quot;Store Url&quot;,<br \/>\n&quot;var logo_url&quot;:&quot;Email Logo Image Url&quot;,<br \/>\n&quot;var logo_alt&quot;:&quot;Email Logo Image Alt&quot;,<br \/>\n}<br \/>\n@&#8211;&gt;<br \/>\n&lt;!&#8211;@styles<br \/>\nbody,td { color:#2f2f2f; font:11px\/1.35em Verdana, Arial, Helvetica, sans-serif; }<br \/>\n@&#8211;&gt;<br \/>\n&lt;body style=&quot;background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;&quot;&gt;<br \/>\n&lt;div style=&quot;background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;&quot;&gt;<br \/>\nHello {{var custName}}&lt;br&gt;<br \/>\nThank you. Your logo path is {{var logo_url}}<br \/>\n&lt;\/div&gt;<br \/>\n&lt;\/body&gt;<br \/>\n[\/php]<\/p>\n<p>\n&lt;!&#8211;@subject : In this tag you can define subject line of your email.<br \/>\n&lt;!&#8211;@vars : In vars section you can define your custom variable.<br \/>\n&lt;!&#8211;@styles : In this tag section you can add custom style for your email template.<br \/>\n{{var custName}} : By using {{var custName}} you can add your custom variable in your email template.\n<\/p>\n<p>\nNow add following code in your module&#8217;s config.xml file&#8217;s global node.\n<\/p>\n<p>[php]<br \/>\n&lt;template&gt;<br \/>\n&lt;email&gt;<br \/>\n&lt;test_email_template&quot;&gt;<br \/>\n&lt;label&gt;Test Email&lt;\/label&gt;<br \/>\n&lt;file&gt;test.html&lt;\/file&gt;<br \/>\n&lt;type&gt;html&lt;\/type&gt;<br \/>\n&lt;\/test_email_template&gt;<br \/>\n&lt;\/email&gt;<br \/>\n&lt;\/template&gt;<br \/>\n[\/php]<\/p>\n<p>\nNow clear magento cache and go to <strong><em>admin &gt; Transactional Email &gt; Add New Template<\/em><\/strong>. From here you can load your cuatom email template\n<\/p>\n<p>\nAdd the following code in your controller&#8217;s action from where you want to send your email.\n<\/p>\n<p>[php]<br \/>\n&lt;?php<br \/>\n$templateId = 25 \/\/your email template id;<br \/>\n$sender = Array(&#8216;name&#8217; =&gt; &#8216;Sender&#8217;s Name&#8217;,<br \/>\n&#8217;email&#8217; =&gt; &#8216;test@test.com&#8217;);<br \/>\n\/\/recepient<br \/>\n$email = &#8216;abc@test.com&#8217;;<br \/>\n$emaiName = &#8216;Sender&#8217;s Name&#8217;;<br \/>\n$vars = Array();<br \/>\n$vars = Array(&#8216;customVariable&#8217;=&gt;$yourCustomVarialbe,<br \/>\n);*\/<br \/>\n$storeId = Mage::app()-&gt;getStore()-&gt;getId();<br \/>\n$translate = Mage::getSingleton(&#8216;core\/translate&#8217;);<br \/>\nMage::getModel(&#8216;core\/email_template&#8217;)<br \/>\n-&gt;sendTransactional($templateId, $sender, $email, $emailName, $vars, $storeId);<br \/>\n$translate-&gt;setTranslateInline(true);<br \/>\n?&gt;<br \/>\n[\/php]<\/p>\n<p>\nThat&#8217;s it. Hope this will help you \ud83d\ude42\n<\/p>\n<p>\n<br \/>\nRegards,<br \/>\nAmatya Trivedi<br \/>\namatya@intelligrape.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &gt; System &gt; 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 [&hellip;]<\/p>\n","protected":false},"author":62,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1},"categories":[1],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/10107"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/62"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=10107"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/10107\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=10107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=10107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=10107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}