When sending order confirmations, I wish to have them all go to a specified email address and disable them going to the customer.

Please note, this is for internal use, where everything is free and no legal requirements to offer invoices/etc. I need to send data for the order and customer via this order email, formatted so that it can be captured by another system.

I found within Magento/vendor/magento/module-sales/Model/Order.php on line 2501:

 * Returns customer_email
 * @return string
public function getCustomerEmail()
    return $this->getData(OrderInterface::CUSTOMER_EMAIL);

and then again on line 4045:

 * {@inheritdoc}
public function setCustomerEmail($customerEmail)
    return $this->setData(OrderInterface::CUSTOMER_EMAIL, $customerEmail);

Editing this works, in that I can redirect all emails to a static address ([email protected]) but it also replaces the customer's email as it appears in the order to the same address ([email protected]). I still need to have the CUSTOMER_EMAIL value = the customer's email as I need to send that within the email as part of the email body.

Which is the right file to edit where the sending of the email is executed so I can change the address there?

Thank you very much in advance!

1 Answer 1


AFAIK email address set in here


prepareTemplate() method

But you can not create prefrence of this class as its abstract.

So what you can do is create prefrence of this clas vendor/magento/module-sales/Model/Order/Email/Sender/OrderSender.php

and with in send() method wrap your code before and after this code $this->checkAndSend($order)

what You can so is

$orignalCustomerAddr = $order->getCustomerEmail();
//after $this->checkAndSend($order) this line below code

Update as per OP requirement

For using $originalCustomerAddr in template you can add one extra array result in prepareTemplate method.

So just add one extra variable like this in $transport result set

    $transport = [
        'order' => $order,
        'billing' => $order->getBillingAddress(),
        'payment_html' => $this->getPaymentHtml($order),
        'store' => $order->getStore(),
        'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
        'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
        'orignalEmail'=> $orignalEmail

And in email template you can use this variable as orignalEmail

  • It worked great, except today I realised that I can't use {{var order.getCustomerEmail()}} inside the order email template to send the customer's email. This is important as I need to push this email address to the other system. So I either need help with another way to send to a fixed address or how I can get the variable $originalCustomerAddr into the email template.
    – Kai
    Jun 13, 2018 at 2:43
  • @Kai check updated answer Jun 13, 2018 at 3:06
  • Thank you for such a quick response, unfortunately, that led to an error that resulted in the email being unable to be sent. Instead of the confirmation "You sent the order email." it returned "We can't send the email order right now." and no email was sent.
    – Kai
    Jun 13, 2018 at 3:22
  • @kai were you get $orignalEmail variable in prepareTemplate method Jun 13, 2018 at 3:36
  • Yes, I had done as you instructed in the section under "Update as per OP requirement".
    – Kai
    Jun 13, 2018 at 4:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.