Based on certain customer data I need to send a copy of the confirmation email to other email addresses.
I created an observer to catch the order data
checkout_onepage_controller_success_action
In my observer class I load all data I need with
Mage::getModel('sales/order')->load($observer->getOrderIds());
That works like a charm.
Now some code is selecting the email address where the copy supposed to go to.
But how can I send a copy of the order confirmation email to (always different) email addresses?
$order->sendNewOrderEmail();
Above doesn’t work for me because I need the recipient as a parameter.
Any help will be much appreciated. Thank you.
Best Answer
Oh that is a tough one. From what I can see you have two options.
sendNewOrderEmail
function so that you do the same stuff and generate the email but just send it to a different address.$copyTo = $this->_getEmails(self::XML_PATH_UPDATE_EMAIL_COPY_TO);
, I know you already have your event and I am not 100% sure what you need but you could change this function,It might not be ideal but if you rewrite the
Mage_Sales_Model_Order
you could then check in the_getEmails
if your conditions meet then you send a copy to where ever you need to, otherwise you continue with the normal sales order. Even as I write this I am not convinced if this is such a good idea, but I cannot see another "easy" way to hock into this without duplicating a lot of code when generating the email.One final not is that the event you have selected
checkout_onepage_controller_success_action
is specific to the onepage checkout so if you create an order via the admin or multiple shipping checkout then your code would not be hit, sadly this has caught me out before :(