0

Im trying to send email using transportbuilder but I'm getting this error.

Exception #0 (Magento\Framework\Exception\MailException): No body specified Exception #1 (Zend_Mail_Transport_Exception): No body specified

The template is already in and everything is already put in. Im using the following code to send email.

$transport = $this->_transportBuilder->setTemplateIdentifier($templateId)
                    ->setTemplateOptions(['area' => \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE, 'store' => $storeId])
                    ->setTemplateVars($vars)
                    ->setFrom($sender)
                    ->addTo($email, $name)
                    ->getTransport();

                $transport->sendMessage();

Can anyone help me on this.

1 Answer 1

1

Issue is in template id..

Template does not set properly.That why it is showing error.

If you have define email from email_templates.xml then

<?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="[TEMPLATE_ID]" label="[TEMPLATE_ID]" file="[TemplateHTMLFILE].html" type="html" module="Vendor_Module" area="frontend"/>
</config>

Then, [TEMPLATE_ID] is template id you should it at setTemplateIdentifier($templateId)

Also,Change and try it

'store' => $storeId

to

\Magento\Store\Model\Store::DEFAULT_STORE_ID

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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