Magento 1.9 – Send orders mails immediately rather than cron

Ab Magento Version 1.9 the order confirmation emails are sent not by Event (So after a successful order) but a mail queue, which is triggered via the cron. In many cases, the order confirmation is therefore only all 15 sent minutes.

not really optimal is just with the order confirmation, because the customer expects this after ordering, to be sure, that has really worked out everything. With invoice mails or shipping confirmations contrast, it's probably not as bad, if they were sent a few minutes later. But they remain sent by Event – so directly.

For people who would like to, that the order confirmation will be sent directly after ordering, can retrofit this relatively straightforward.

Hierzu kopiert man die Datei app/code/core/Mage/Sales/Model/Order.php in den Ordner app/code/local/Mage/Sales/Model/Order.php

und sucht dort nach der Zeile

$mailer->setQueue($emailQueue)->send();

This is commented out or deleted and replaced by this line

$mailer-> send();

Subsequently, then the app / design / frontend /[IhrTemplate]/[IhrTemplate]/template / checkout / open success.phtml and top yet ago closing the ?> the following code integrated:

//Order confirmation without cron
$ order = Mage::getModel('sales/order');
$incrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order->loadByIncrementId($incrementId);

try{ $order->sendNewOrderEmail();}
catch (Exception $ex) { echo "Email Not Sent..."; }
$customer = Mage::getSingleton('Customer / session')->getCustomer();
$email = $customer->getEmail();

Then eventually clear the cache again. Now the mails coming but directly after ordering.

Update vom 17.02.2017

It struck, that repeatedly order confirmation emails were sent twice. To fix this, changing the success.phtml was undone (s.o.). So if the problem of duplicate email shipment emerge, then remove this adjustment again and change only the order.php.

Update vom 25.07.2017

If the o.g. Way do not work, a different way can be traced:

Man kopiert app/code/core/Mage/Core/Model/Email/Template.php nach

app/code/local/Mage/Core/Model/Email/Template.php

and from there, then the line (as. 407-426)

        if ($this->hasQueue() && $this->getQueue() instanceof Mage_Core_Model_Email_Queue) {
            /** @var $ emailQueue Mage_Core_Model_Email_Queue */
            $emailQueue = $this->getQueue();
            $emailQueue->clearRecipients();
            $emailQueue->setMessageBody($text);
            $emailQueue->setMessageParameters(array(
                    'subject'           => $subject,
                    'return_path_email' => $returnPathEmail,
                    'is_plain'          => $this->isPlain(),
                    'from_email'        => $this->getSenderEmail(),
                    'from_name'         => $this->getSenderName(),
                    'reply_to'          => $this->getMail()->getReplyTo(),
                    'return_to'         => $this->getMail()->getReturnPath(),
                ))
                ->addRecipients($emails, $names, Mage_Core_Model_Email_Queue::EMAIL_TYPE_TO)
                ->addRecipients($this->_bccEmails, array(), Mage_Core_Model_Email_Queue::EMAIL_TYPE_BCC);
            $emailQueue->addMessageToQueue();

            return true;
        }

Without replacement. Then the order confirmation was sent immediately.

Update vom 19.01.2018

Also in connection with part no more incoming mails, Please have a look in THIS throw Post – using the Extension SMTP Pro can see the mail queue of Magento 1.9 handle comfortably and without code modification.

Used in Magento Version 1.9 Comments? Additions? Notes? Gladly!

Published by Covos

Since 2009 I have been working intensively with Magento. I started with the creation and operation of B2C stores. This was extended through my work in the logistics sector. This resulted first specialized B2E systems. Today I work day-a day with exciting B2C, B2B- and B2E projects and reports in this blog about challenges and give insider tips.

13 comments on “Magento 1.9 – Send orders mails immediately rather than cron”

    1. here the same problem. not constantly, but only sporadically / occasionally.
      absolutely for mice-milking……

  1. Hi in my installation of Magento 1.9.3.6 there is the 2. no path. The path exists: app/code/core/Mage/Sales/Model/Order.php
    the non-: app/code/local/Mage/Sales/Model/Order.php

    with me in it:
    app/code/local/smartwave
    and
    app/code/local/Magegiant

    I have now the Sales folder look elsewhere?

    Thanks for the reply. lg Marcel

  2. Thank you for those tricks,
    Indeed the client receive the confirmation mail but the admin do not
    Can you help please

    1. Hi!
      This can have different reasons. One of them is that your mail hoster is not allowing receiving mails from the “fake” smtp-server which Magento is using in standard. So you’ll need to use a real smtp-server. Please refer to my article about SMTP-pro extension in this blog. With this you can log all mails and see whether the admin mails are actually sent or not. This will bring you further finding the problem.
      Regards!

      1. Thank you for the response,
        I install the extension, but always the same problem for admin,
        Indeed the client receive its confirmation, and the contact mail is sent too
        Can you help me please
        thank you

Leave a Reply

Your email address will not be published. Required fields are marked *