How to disable email sending when programatically creating an order in Magento

Here is a little snippet of code that can come in handy if you are like me handling a task of programatically creating an order in Magento. My issue was that I had to disable emails beeing sent out to the customers, while at the same time leave the normal frontend process. Thus I could not just go under Magento admin System > Congifuration and disable email sending from there.
Here is the sample line code you just need to place above final $order->save() or possibly $checkout->saveOrder():
Mage::app()->getStore()->setConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_ENABLED, "0");
11 comments
Hi, do you know how can I disable confirmation email when I creat order via API? Your code doesn’t work for API.
My magento site are not work email correctly when order the product from customer.Who’s will you help me?
How to stop email sending when creating order from back end in magento.
i using email :-
1234@schoolwear.in,
12345@schoolwear.in
12345@schoolwear.in,
etc.
so this is effecting in bounce email.
so i want need stop to send all company email only in magento.
please help me
@robin
This worked for me
in a custom customer.php file we have. Worked for my english store, but not in my french store. ;P
@robin
sure you can…
try to trace the code in the class:
and trace which XML_PATH you need
Can I disable the welcome e-mail?
I have a silent account creation so customers don’t need to register explicitly, but an account is made so they can check their order status.
They receive 3 e-mails when placing an order: welcome email, separate password email and confirmation email
Can I disable the Order Confirmation email only ?
Customers receive 3 auto emails.
Order confirmation, order complete & Order shipped.
latter are processed at the same time and are redundant.
Thanks –
Hi,
thanks for sharing this tip, but I havea slightly different problem and maybe you can help.
When I’m enabling the ordermail system-> configuration -> Sales Email -> Order
both the customer and the admin get the same email.
But I just want the admin to get the email because theres another backend sending the emails to the customer.
Do you have an idea?
Interestingly this doesn’t seem to work with the newsletter subscription. The email is still sent.
This is on CE 1.4.
@Jonathan
Config is not saved so you don’t need to turn anything back. This code is merely used to overide saved config value at the moment you need it.
nice. I assume it needs to be turned back on again after saving the order?