Magento Admin Configurable Email Notification System

Notification is very important features on website, sometimes we need to send mail based on our product stock. Magento is also providing notification for his core module but if you need your own notification system then this article helps you, You can create your own email system with configurable options, means you can change toEmail and fromEmail option form magento admin UI.
You can also check other tutorial of magento theme,

First we will create admin UI template to add/edit notification parameters. We need to edit sytem.xml file of sales module and add below code after end of file.
[code type=xml]


text
9
1
1
1



selectadminhtml/system_config_source_yesno
1
1
1
1



text
0
1
1
1



text
1
1
1
1



text
2
1
1
1


Above xml code will create admin UI where you can change your configuration parameters. Now we will write our logic to get these parameters in php function and send mail to target users.

/** 
    * @function         : sendErrorEmail 
    * @created by       : Parvez Alam 
    * @creation date    :  
    * @description      : This method used for send error 
    * @params           : error email  
    * @returns          : int 
    */  
    public function sendErrorEmail($errMsg)  
    {   
        $fromEmail = Mage::getStoreConfig(‘sales_email/erroremail/fromemail’); // sender email address  
        $fromName = Mage::getStoreConfig(‘sales_email/erroremail/fromname’); // sender name  
        $toEmail = Mage::getStoreConfig(‘sales_email/erroremail/toemail’); // recipient email address  
        $toName = Mage::getStoreConfig(‘sales_email/erroremail/toname’); // recipient name  
        $detailsErrmsg=“Hi,”.”  
“.”Following is system generated error accured.”;  
        $body = $detailsErrmsg.”  
“.$errMsg; // body text  
        $subject = “System Generated Kiosk Error”; // subject text  
       
        $mail = new Zend_Mail();          
        //$mail->setBodyText($body);  
        $mail->setBodyHtml($body);  
        $mail->setFrom($fromEmail, $fromName);  
        $mail->addTo($toEmail, $toName);  
        $mail->setSubject($subject);  
        try   
        {  
            $mail->send();  
            return 1;  
        }  
        catch(Exception $ex)   
        {  
            // I assume you have your custom module.  
            // If not, you may keep ‘customer’ instead of ‘yourmodule’.  
            return 0;  
        }  
    }