I want to add an image of the product in the mail send after a successful checkout.

I am so far that I made a module that overrides


But how to insert an image thumbnail?


* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.

// @codingStandardsIgnoreFile

<?php $_order = $block->getOrder() ?>
<?php if ($_order): ?>
<?php $_items = $_order->getAllItems(); ?>
<table class="email-items">
            <th class="item-info">
                <?= /* @escapeNotVerified */  __('Items'); ?>
            <th class="item-qty">
                <?= /* @escapeNotVerified */  __('Qty'); ?>
            <th class="item-price">
                <?= /* @escapeNotVerified */  __('Price'); ?>
    <?php foreach ($_items as $_item): ?>
            if ($_item->getParentItem()) {
            <?= $block->getItemHtml($_item) ?>
    <?php endforeach; ?>
    <tfoot class="order-totals">
        <?= $block->getChildHtml('order_totals') ?>
<?php if ($this->helper('Magento\GiftMessage\Helper\Message')->isMessagesAllowed('order', $_order, $_order->getStore()) && $_order->getGiftMessageId()): ?>
    <?php $_giftMessage = $this->helper('Magento\GiftMessage\Helper\Message')->getGiftMessage($_order->getGiftMessageId()); ?>
    <?php if ($_giftMessage): ?>
        <br />
        <table class="message-gift">
                    <h3><?= /* @escapeNotVerified */  __('Gift Message for this Order') ?></h3>
                    <strong><?= /* @escapeNotVerified */  __('From:'); ?></strong> <?= $block->escapeHtml($_giftMessage->getSender()) ?>
                    <br /><strong><?= /* @escapeNotVerified */  __('To:'); ?></strong> <?= $block->escapeHtml($_giftMessage->getRecipient()) ?>
                    <br /><strong><?= /* @escapeNotVerified */  __('Message:'); ?></strong>
                    <br /><?= $block->escapeHtml($_giftMessage->getMessage()) ?>
    <?php endif; ?>
<?php endif; ?>

I did that by copying vendor/magento/module-sales/view/frontend/templates/email/items/order/default.phtml to my template folder app/design/frontend/[VENDOR]/[TEMPLATE]/Magento_Sales/templates/email/items/order/default.phtml and adding the image column there...

$_item = $block->getItem();
$_order = $_item->getOrder();
$_store = $_order->getStore();

$_imageHelper = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Catalog\Helper\Image');
$_baseImageUrl = $_store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA).'catalog/product';

and right below

<img src="<?= $_imageHelper->init($_item->getProduct(), 'small_image', ['type'=>'small_image'])->keepAspectRatio(true)->resize('65','65')->getUrl();?>" alt="<?= __('Product Image');?>">
  • Do I insert the <img src= code right below the $_baseImageUrl = code? The reason I ask is that I'm getting a syntax error when I do and just wanted to make sure? Thanks for the help.
    – Rudy C.
    Oct 25 '18 at 17:03
  • What kind of syntax error are you having? (remember to enable short_open_tag on php.ini) Oct 25 '18 at 22:31
  • Image is not displaying, URL looks like this by inspecting: ci4.googleusercontent.com/proxy/… Any way to solve gmail proxy server issue? image displays if I visit localhost.test/pub/static/version160085/frontend/MyTheme/…
    – Ajwad Syed
    Mar 7 '21 at 7:17
  • GMail will always add a proxy layer in all images. There's nothing you can do about that (if its the case). You can click on "View Original" and inspect the source code to double check if your url is correct. Mar 8 '21 at 1:07

As addition to Ricardo Martins answer. I had to show the children product image of configurable products. Here is the code for those who have the same problem .

    <?php if($childProd = current($_item->getChildrenItems())):  ?>
        <img src="<?= $_imageHelper->init($childProd->getProduct(), 'small_image', ['type'=>'small_image'])->keepAspectRatio(true)->resize('65','65')->getUrl();?>" alt="<?= __('Product Image');?>">
    <?php else: ?>
        <img src="<?= $_imageHelper->init($_item->getProduct(), 'small_image', ['type'=>'small_image'])->keepAspectRatio(true)->resize('65','65')->getUrl();?>" alt="<?= __('Product Image');?>">               
    <?php endif; ?> 

Actually, I did not tried in magento-2 version. But i tried in Magento-1.9 version. I got the result.

Please go through Product Thumbnail in sales-order emails this link of magento connect manager for product thumbnail image in order emails.

  • This is something i want, but not compatible with magento 2.... Nov 28 '16 at 10:07
  • No solution yet.... Nov 30 '16 at 14:25
  • A change in the default.phtml dit not influence the email at all. Also if i change it in the root folder manually nothing happend. Items.phmtl is what i need to influence, and that's working now. But how to get an image there... Nov 30 '16 at 14:46

I'll admit that this is bad form, and it should be refactored into a proper module that uses Dependency Injection instead of the ObjectManager...

That said, there is some basic code I got working which renders the Simple Product variation image of a Configurable product, if you have that option enabled in the Minicart.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = null;

// Look up the simple product SKU
if ($sku = $_item->getProductOptionByCode('simple_sku')) {
    $productRepositoryInterface = $objectManager->get('\Magento\Catalog\Api\ProductRepositoryInterface');
    // get the simple product
    try {
        $product = $productRepositoryInterface->get($sku);
    } catch (Exception $e) {
        // this throws an exception if not found, so catch it
        if ($e->getMessage() != 'Requested product doesn\'t exist') {
            throw $e;

// if no simple product, get the usual product ID
if (!$product) {
    $product_id = $_item->getProductId();
    $product = $objectManager->get('Magento\Catalog\Model\Product')->load($product_id);

// now load the image for that product
$_imagehelper = $this->helper('Magento\Catalog\Helper\Image');
$image_url = $_imagehelper->init($product, 'cart_page_product_thumbnail')->getUrl();
  • iam getting only one category image May 12 '18 at 13:09

This can help one to get both simple product image and child product img of config products.

So override magento file to YourNamespace/app/design/frontend/Magento/ThemeName/Magento_Sales/templates/email/items/order/default.phtml

Add the following code above

    $_item = $block->getItem();
    $product = $_item->getProduct();
    $_baseImageUrl = $_store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA).'catalog/product';
    if($childProd = current($_item->getChildrenItems())) {
        $productImage = $_baseImageUrl . $childProd->getProduct()->getImage();
    else {
        $productImage = $_baseImageUrl . $product->getImage();

And you can add any custom html mods below this and under an img src tag to call the image at desired location:

<img src="<?= $productImage?>" alt="<?= __('Product Image');?>" width="70" height="70">

Your Answer

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

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