Hello,
I recently upgraded from 2.4.2 to 2.4.5-p1 and my email order confirmations no longer work.
My variables were all in the format {{var order.getBillingAddress().format('html')}}
but now they are like this {{var formattedBillingAddress|raw}}
In my previous order confirmations I would include the customer email address just below the billing address using:
{{var order.getCustomerEmail()}}
But this no longer works with 2.4.5
This is something that changed with 2.4.4
Anyone know what the variable for customer email under the new system?
I looked around and tried a few things, but nothing worked.
TIA
{{var order_data.customer_email}}
What about that?
Hi @racicot6977e3e ,
Create events.xml file on app/code/Vendor/Module/etc
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="email_order_set_template_vars_before">
<observer instance="Vendor\Module\Observer\Email\OrderSetTemplateVarsBefore" name="v4u_emailvar_observer_email_ordersettemplatevarsbefore_email_order_set_template_vars_before"/>
</event>
</config>
Create OrderSetTemplateVarsBefore.php on app/code/Vendor/Module/Observer/Email
<?php
/**
* Copyright © All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Vendor\Module\Observer\Email;
use Magento\Customer\Api\CustomerRepositoryInterface;
class OrderSetTemplateVarsBefore implements \Magento\Framework\Event\ObserverInterface
{
protected $customerRepository;
public function __construct(
CustomerRepositoryInterface $customerRepository
) {
$this->customerRepository = $customerRepository;
}
/**
* Execute observer
*
* @param \Magento\Framework\Event\Observer $observer
* @return void
*/
public function execute(
\Magento\Framework\Event\Observer $observer
) {
/** @var \Magento\Framework\App\Action\Action $controller */
$transport = $observer->getEvent()->getTransport();
if($transport->getOrder() != null)
{
$customer = $this->customerRepository->getById($transport->getOrder()->getCustomerId());
$transport['customer_email'] = $customer->getEmail();
}
}
}
Email Template you can use it like below:
{{var customer_email}}
Problem Solved? Accept as Solution!
No this didn't work.
The email address was blank on the order confirmation.
Thanks for trying...
Hello racicot6977e3e,
When an order is made, online stores must automatically send a sales email or order confirmation to their customers, which is done via configuration in Magento 2. But, If you're facing order Confirmation emails not working problem after the upgrade, you can follow the below ways to fix the issue,
Check the configuration on the admin page:
Check server configuration:
<?php mail ('you@example.com', "Test Postfix", "Test mail from postfix"); ?>
Note: You will have to enter your email address in place of 'you@example.com'
You need to check the server settings if you don't receive any emails using the above code.
You must check the Var/log to find any warning or error related to mail, and check the following configuration:
Also, verify your Host and Port fields, If using any external mailing server.
If the issue persists, you must ensure your cronjob setup on your hosting panel or server is running, as it might be causing email delays. In addition, you must also check your payment gateways once, as it can also cause the "order Confirmation emails not working" problem.
Thus, I hope the above solution helps you fix the "order Confirmation emails not working after upgrade" issue.
-------------------------------
Regards,
Rex M