I have made a custom module to send out a custom message when an order is placed. I can successfully get custom message to be sent out by email. But the problem is, the Magento order email will not be sent out. And if I disable the module, or simply commented out the email function out in my custom module, then the order email is working again.

I'm using events sales_order_place_after for triggering my module.

And below is the email function.

public function execute(\Magento\Framework\Event\Observer $observer)
$orderid = "qqqq";
$comment = " test comment";
$emailTempVariables = array();
$emailTempVariables['orderid'] = $orderid;
$emailTempVariables['comment'] = $comment;

$senderName = 'test_sender';
$senderEmail = 'sender@example.com';

$email = "receiver@example.com";

$postObject = new \Magento\Framework\DataObject();

$sender = [
    'name' => $senderName,
    'email' => $senderEmail,

$transport = $this->transportBuilder->setTemplateIdentifier('myemail_email_template')
    ->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])
    ->setTemplateVars(['data' => $postObject])
    // ->setReplyTo($senderEmail)

    return $this;

Please note that this function is working fine, and I can successfully get email sent out. It's just when this is enabled, then Magentos order email will stop working.

How can I get both my custom email function and Magentos order email to be working at the same time?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.