Search code examples
magento-1.9

How to send custom email in magento


I am very new to MAGENTO, I have build a brand new extension. So i have created form now i want to send all details in html to admin as well as guest user.

   $mail = new Zend_Mail();
   $mail->setBodyText($mydata);
   $mail->setFrom($guestEmail); 
   $mail->addTo('[email protected]', 'Some Recipient');
   $mail->setSubject('Test su');
   $mail = Mage::getModel('core/email'); 

Thanks for help.


Solution

  • try out this code i think i have already answered it :--

    <?php
    class Arunendra_Headerchanger_IndexController extends Mage_Core_Controller_Front_Action{
       public function sendemailAction()
        {
            //Fetch submited params
            $params = $this->getRequest()->getParams();
            $firstName = $this->getRequest()->getParams('First-Name');
            $lastName = $this->getRequest()->getParams('Last-Name');
            $email = $this->getRequest()->getParams('Email');
            $fullName = $firstName.' '. $lastName;
    
            $result = array_filter($params, 'strlen' );
            $str = '<table><tr><th>Field:</th><th>Value:</th></tr>';
            foreach($result as $key => $value){
            $str .='<tr>';
            $str .=  '<td>'.$key.':</td><td>'.$value.'</td>';
            $str .= '</tr>';
    
            }
            $str .=  '</table>';    
            $mail = Mage::getModel('core/email');
            $mail->setToName('Arunendra');
            $mail->setToEmail('[email protected]');
            $mail->setBody($str);
            $mail->setSubject('Pre-Employment Application');
            $mail->setFromEmail($email);
            $mail->setFromName($fullName);
            $mail->setType('html');// You can use 'html' or 'text'
            try {
                $mail->send();
                Mage::getSingleton('core/session')->addSuccess('Your request has been sent');
            }        
            catch(Exception $ex) {
                Mage::getSingleton('core/session')->addError('Unable to send email.');
    
            }
    
            //Redirect back to index action of (this) inchoo-simplecontact controller
                 $this->_redirect('careerform');
        }
    
    }