How to send email to multiple users in magento

This is my code that works great when I send it to one recipient, i.e. if I use ' rec1@gmail.com ' (single email address), it works fine. However, I also want to include the second email identifier rec2@gmail.com and write the code as follows: ' rec1@gmail.com , rec2@gmail.com ' , but this does not work.

Let me know how I can implement this functionality?

 $templateId = 1; $sender = array( 'name' => 'swapnesh', 'email' => ' sender@gmail.com ' ); $store = Mage::app()->getStore(); $vars = array( 'my_var' => 15, 'another_var' => 12 ); $translate = Mage::getSingleton('core/translate'); // Send your email Mage::getModel('core/email_template')->sendTransactional( $templateId, $sender, ' rec1@gmail.com , rec2@gmail.com ', 'Recipient Name', $vars, $store->getId() ); $translate->setTranslateInline(true); 
+4
source share
2 answers

The answer is in Mage_Core_Model_Email_Template::send()

You can see that the arguments $email and $names can be like arrays. So in your case, if there is:

 $recipients = [ ' rec1@gmail.com ' => 'Recipient1 Name', ' rec2@gmail.com ' => 'Recipient2 Name' ]; Mage::getModel('core/email_template')->sendTransactional( $templateId, $sender, array_keys($recipients), array_values($recipients), $vars, $store->getId() ); 
+8
source

To send email to multiple recipients in Contact Us Magento, you can tray this way.

Step one, you can find this line in the /code/core/Mage/Contacts/Controllers/IndexController.php application

 $mailTemplate = Mage::getModel('core/email_template'); /* @var $mailTemplate Mage_Core_Model_Email_Template */ $mailTemplate->setDesignConfig(array('area' => 'frontend')) ->setReplyTo($post['email']) ->sendTransactional( Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE), Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER), Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT), null, array('data' => $postObject) ); 

and modified below:

  $recipients = Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT); if ($recipients) { $recipients = explode(";",$recipients); if(count($recipients)) { foreach($recipients as $recipient) { $mailTemplate = Mage::getModel('core/email_template'); /* @var $mailTemplate Mage_Core_Model_Email_Template */ $mailTemplate->setDesignConfig(array('area' => 'frontend')) ->setReplyTo($post['email']) ->sendTransactional( Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE), Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER), $recipient, null, array('data' => $postObject) ); if (!$mailTemplate->getSentSuccess()) { throw new Exception(); } } } } 

And don't forget to comment on javascript validation on app / code / core / Mage / Contacts / etc / system.xml

Find this line:

 <recipient_email translate="label"> <label>Send Emails To</label> <frontend_type>text</frontend_type> <!--<validate>validate-email</validate>--> <sort_order>10</sort_order> <show_in_default>1</show_in_default> <show_in_website>1</show_in_website> <show_in_store>1</show_in_store> </recipient_email> 

Comment on this line <validate>validate-email</validate>

this code works for me in magento 1.7.0.2. Hope this helps your problem ..: D

Remember to save and clear the cache.

-2
source

Source: https://habr.com/ru/post/1437777/


All Articles