0

I want send custom email with custom module in magento.I have successfully send email to customer after submit inquiry. now need to send custom email to admin with diffrent template. i.e customer email template can only send to customer and admin email can only send to admin with relative template after form submit.

following is my IndexController.php

<?php
class Pfy_Contactus_IndexController extends  Mage_Core_Controller_Front_Action{
public function IndexAction() {

  $this->loadLayout();   
  $this->getLayout()->getBlock("head")->setTitle($this->__("Contactus"));
        $breadcrumbs = $this->getLayout()->getBlock("breadcrumbs");
  $breadcrumbs->addCrumb("home", array(
            "label" => $this->__("Home Page"),
            "title" => $this->__("Home Page"),
            "link"  => Mage::getBaseUrl()
       ));

  $breadcrumbs->addCrumb("contactus", array(
            "label" => $this->__("Contactus"),
            "title" => $this->__("Contactus")
       ));

  $this->renderLayout(); 

}

/**
* Ajax reuest to quote
*/
public function UpdateinfoAction() {

    $email = $this->getRequest()->getParam('email');
    $number = $this->getRequest()->getParam('number');  
    $comment = $this->getRequest()->getParam('comment');    
    $data = array(
        'email' => $email,  
        'number' => $number,            
        'comment' => $comment                 
    );
    $model = Mage::getModel('contactus/contactus'); //for eg. Mage::getModel('catalog/product');
    try {
        $model->setData($data)
            ->save();

             $jsonData = json_encode(array('error' => false));
            $this->getResponse()->setHeader('Content-type', 'application/json');
            $this->getResponse()->setBody($jsonData);
            $this->sendEmail($email, $number);
    } catch (Exception $e) {
        echo $e->getMessage();
    }       
}
function sendEmail($email, $number)
{   
templateId = 9;
 $sendername = Mage::getStoreConfig('trans_email/ident_general/name');
 $senderemail = Mage::getStoreConfig('trans_email/ident_general/email');
 $sender = Array('name' => $sendername,
 'email' => $senderemail);
 //recepient

 $email = $email;
 $number = $name;
 $vars = Array();
 $vars = Array('email' => $email,'number' => $number);
 $storeId = Mage::app()->getStore()->getId();
 $translate = Mage::getSingleton('core/translate');
 Mage::getModel('core/email_template')
->sendTransactional($templateId, $sender, $email, $number, $vars, $storeId);
$translate->setTranslateInline(true);
}
}

this is my config.xml file template tag is under tag.

<template>
        <email>
            <contactus_email_template translate="label"   module="contactus">
                <label>Inquiry Now</label>
                <file>inquiry_now.html</file>
                <type>html</type>
            </contactus_email_template>
         </email>   
 </template>

thanks in advance

1 Answer 1

0

You need to create new template for admin. Code as below:

<template>
        <email>
            <contactus_email_template translate="label"   module="contactus">
                <label>Inquiry Now</label>
                <file>inquiry_now.html</file>
                <type>html</type>
            </contactus_email_template>
            <contactus_admin_email_template translate="label"   module="contactus">
                <label>Inquiry From Customer</label>
                <file>inquiry_now_admin.html</file>
                <type>html</type>
            </contactus_admin_email_template>
         </email>   
 </template>

You need to write email send code two times with appropriate template id and sender and receiver email one for admin and second for customer as below:

templateId = 9;
 $sendername = Mage::getStoreConfig('trans_email/ident_general/name');
 $senderemail = Mage::getStoreConfig('trans_email/ident_general/email');
 $sender = Array('name' => $sendername,
 'email' => $senderemail);
 //recepient

 $email = $email;
 $number = $name;
 $vars = Array();
 $vars = Array('email' => $email,'number' => $number);
 $storeId = Mage::app()->getStore()->getId();
 $translate = Mage::getSingleton('core/translate');
 Mage::getModel('core/email_template')
->sendTransactional($templateId, $sender, $email, $number, $vars, $storeId);
$translate->setTranslateInline(true);

//For admin

templateId = "admin template id goes here";
 $sendername = Mage::getStoreConfig('trans_email/ident_general/name');
 $senderemail = Mage::getStoreConfig('trans_email/ident_general/email');
 $sender = Array('name' => $sendername,
 'email' => $senderemail);
 //recepient

 $email = $email;
 $number = $name;
 $vars = Array();
 $vars = Array('email' => $email,'number' => $number);
 $storeId = Mage::app()->getStore()->getId();
 $translate = Mage::getSingleton('core/translate');
 Mage::getModel('core/email_template')
->sendTransactional($templateId, $sender, $email, $number, $vars, $storeId);
$translate->setTranslateInline(true);
3
  • but how can i send email to appropriate email is
    – Neeya
    Dec 16, 2016 at 5:27
  • but how can i send email to appropriate email id?
    – Neeya
    Dec 16, 2016 at 5:37
  • change $email variable value with your receiver email id Dec 16, 2016 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.