0

i'm debugging a email function, the there is an exception terminate the program

<? public function merchantEmailAction( ) { $r = $this->getRequest(); $id = $r->getParam('id'); $deal = Mage::getModel('deals/deal')->load($id, 'product_id'); $merchant_id = $deal->merchant_id; $merchant = Mage::getModel('deals/merchant')->load($merchant_id); $name = $merchant->getMerchantName(); $merchant_email = $merchant->getMerchant_email(); if ( !name ) { $to_name = "Merchant"; } else { $to_name = $name; } $emailTemplate = Mage::getModel('core/email_template')->loadByCode('dailydeals_notification_merchant_email_template'); $storeId = Mage::app()->getStore()->getStoreId(); $sender = array("email" => Mage::getStoreConfig("deals/general/sender_emailid", $storeId), "name" => Mage::getStoreConfig( "deals/general/sender_name", $storeId)); $mail = Mage::getModel('core/email_template'); $emailInfo = Mage::getModel('core/email_info'); $emailInfo->addTo((string)$merchant_email, (string)$to_name); $mail->addEmailInfo($emailInfo); die(); } ?> 

report generated

a:5:{i:0;s:1124:"Invalid method Mage_Core_Model_Email_Template::addEmailInfo(Array ( [0] => Mage_Core_Model_Email_Info Object ( [_bccNames:protected] => Array ( ) [_bccEmails:protected] => Array ( ) [_toNames:protected] => Array ( [0] => Array ( [0] => ABC ) ) [_toEmails:protected] => Array ( [0] => Array ( [0] => [email protected] ) ) [_data:protected] => Array ( ) [_hasDataChanges:protected] => [_origData:protected] => [_idFieldName:protected] => [_isDeleted:protected] => [_oldFieldsMap:protected] => Array ( ) [_syncFieldsMap:protected] => Array ( ) ) ) )";i:1;s:1090:"#0 /home/test1/public_html/app/code/local/customext/Deals/controllers/Adminhtml/DealController.php(461): Varien_Object->__call('addEmailInfo', Array) #1 /home/test1/public_html/app/code/local/customext/Deals/controllers/Adminhtml/DealController.php(461): Mage_Core_Model_Email_Template->addEmailInfo(Object(Mage_Core_Model_Email_Info)) #2 /home/test1/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(418): customext_DailyDeals_Adminhtml_DealController->merchantEmailAction() #3 /home/test1/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('merchantEmail') #4 /home/test1/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http)) #5 /home/test1/public_html/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch() #6 /home/test1/public_html/app/Mage.php(684): Mage_Core_Model_App->run(Array) #7 /home/test1/public_html/index.php(87): Mage::run('', 'store') #8 {main}";s:3:"url";s:95:"/index.php/deals/adminhtml_deal/merchantEmail/id/172/key/5da1fd615e59adf472a55947b67ae5f0/";s:11:"script_name";s:10:"/index.php";s:4:"skin";s:5:"admin";} 

anyone know what is the problem?

2 Answers 2

1

addEmailInfo doesn't exist within the class you've instantiated (Mage_Core_Model_Email_Template).

It exists within Mage_Core_Model_Email_Template_Mailer

If you want to use that method, you'll need to instantiate the class as below:

Mage::getModel('core/email_template_mailer') 

See below for this being used in-context (Mage/Admin/Model/User.php):

$mailer = Mage::getModel('core/email_template_mailer'); $emailInfo = Mage::getModel('core/email_info'); $emailInfo->addTo($this->getEmail(), $this->getName()); $mailer->addEmailInfo($emailInfo); 

However, I suspect this isn't the correct class for your usage anyway, which is where the other answers comes in.

1

The error message is straight forward. There is no method addEmailInfo in the class Mage_Core_Model_Email_Template.
If you want to add recipients to the email do this:

After

$mail = Mage::getModel('core/email_template'); 

add this

$mail->getMail()->addTo($merchant_email, '=?utf-8?B?' . base64_encode($to_name) . '?=') 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.