I need to get the value of an email variable in a phtml file so I can test the value.

In transactional emails I would use, as an exmaple

<td>"Delivery Date" : {{var deliveryDate}}</td>

to render the order specific value for the order delivery but that doesn't work in phtml if I try and do something like

<?php $originaldate = {{var deliveryDate}}; ?>
<?php $newDate =  date('Y-m-d', strtotime($originaldate. ' + 10 days')); ?>
<?php echo $newDate; ?>

When I do this it doesn't return a value and I don't know how to get order or transactional email variables in phtml.

Sorry if this a bit basic but I'm a bit new to some of this and would appreciate your help.

  • share your phtml file code
    – Mohit Rane
    Jul 25, 2019 at 9:43
  • What's the easiest way to do that?
    – wjp_bill
    Jul 25, 2019 at 9:54
  • if you want value in phtml file than you can use $block-> and then the method name for getting deliverydate value.
    – Mohit Rane
    Jul 25, 2019 at 9:57
  • Thank you. How do i get the method name? In an email template I just use {{var deliveryDate}} do you mean something like <?php echo __('Delivery date') . ': ' . $block->escapeHtml($order->getShqDeliveryDate()) ?>
    – wjp_bill
    Jul 25, 2019 at 10:00
  • yes, you got it right
    – Mohit Rane
    Jul 25, 2019 at 10:03

1 Answer 1


I've found a lot of the email logic abstract and you are right. In one or two places it is difficult to follow. One of the simpler examples is the contact us form. I'm bringing together logic from several files but in summary you have the $_POST variables

$post = $this->getRequest()-getPostValue();

Which means you could dump out name

$name = $this->getRequest()->getPostValue('name');

Before the rest of the journey works like this...

Variables for template

$variables = ['data' => new DataObject($post)];

Building email

        $storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
        $transport = $this->transportBuilder
                    'area' => Area::AREA_FRONTEND,
                    'store' => $this->storeManager->getStore()->getId(),
            ->setReplyTo($replyTo, $replyToName)


Email html

    <td><strong>{{trans "Name"}}</strong></td>
    <td>{{var data.name}}</td>

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.