4

I'm trying to use the transportbuilder to send an custom email in my module. I succeed in sending an email, but the body is always empty.

This is my email_templates.xml (placed in view/frontend/email/)

    <?xml version="1.0"?>

    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
        <template id="empty_email_template" label="Empty Template" file="empty.html" type="text" module="Xaiamedia_SyncProducts" area="frontend"/>
    </config>

And this is my mail function:

    $emailTemplateVariables = array();
    $emailTempVariables['ucdata'] = 'dummy';

    $sendToEmail = 'email@gmail.com';

    $postObject = new \Magento\Framework\DataObject();
    $postObject->setData($emailTempVariables);

    $sender = array('email' => "info@mywebsite.nl", 'name' => 'Mywebsite');

    $transport = $this->_transportBuilder->setTemplateIdentifier('empty_email_template')
    ->setTemplateOptions(['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID])
    ->setTemplateVars(['data' => $postObject])
    ->setFrom($sender)
    ->addTo($sendToEmail)
    ->setReplyTo($sender['email'])            
    ->getTransport();               
    $bla = $transport->sendMessage();

And this is my template:

    <strong>De volgende producten zijn verwijderd door Lightmakers:</strong>                <br><br>
    <pre>
    {{trans "Ucdata: %ucData" ucData=$data.ucdata}}
    </pre>

The email is fully blank (no static template content aswell), but I don't get any error messages while sending. Is there a way to debug this situation?

  • did you debug this? – CompactCode Dec 2 '17 at 18:46
  • Did you find the answer? Same issue here. – Coen Ponsen Jan 24 '18 at 9:40
0

Magento sending empty mail reason is module can not access email template.

Your Sending email code is ok.

You have some directory related issue in putting file . Follow bellow step.

=> Step 1 : Put bellow email_templates.xml in Xaiamedia_SyncProducts/etc/ folder

<?xml version="1.0"?>

    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
        <template id="empty_email_template" label="Empty Template" file="empty.html" type="text" module="Xaiamedia_SyncProducts" area="frontend"/>
    </config>

=> Step 2 : put your defined html empty.html to bellow directory

Xaiamedia_SyncProducts/view/frontend/email/empty.html

All Done!

0
<template id="empty_email_template" label="Empty Template" file="empty.html" type="text" module="Xaiamedia_SyncProducts" area="frontend"/>

Change

`type="text"` to  `type="html"`

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.