How to bind product image to email in Magento2.2.5?
I have created custom module in which I need to bind product image to email template in Magento2.2.5?
My code:
$requestData["imgUrl"] = $data["shareProdImg"];
$postObject = new \Magento\Framework\DataObject();
$postObject->setData($requestData);
$transport = $this->transportBuilder
->setTemplateIdentifier('custom_pdp_email_template')
->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])
->setTemplateVars(['data' => $postObject])
->setFrom(['name' => $data["userName"],'email' => $data["userMail"]])
->addTo($data["shareMail"])
->getTransport();
$transport->sendMessage();
My template file:
<li style="font-weight:300;color:black !important;font-family: lato;font-size:16px;margin-left:0;">
{{depend data.imgUrl}}
{{trans "%imgUrl" imgUrl=$data.imgUrl}}<br/>
{{/depend}}
</li>
<li style="font-weight:300;color:black !important;font-family: lato;font-size:16px;margin-left:0;">
<img alt="" data-bind="attr: { src: getImagepaypal() }" alt="Custom image" width="60" height="60">
</li>
Any help would be appreciated.
Solutions
You have to punch to $data["shareProdImg"]
add to $postObject.
$postObject['imgUrl'] = $data["shareProdImg"];