0

I Want to send a url to customer from admin panel custom form. I use below steps to perform the task.

1 - email_templates.xml file content

<?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="ayakil_hometry_email_carturl_template" label="Home Try On Cart Url" file="hometry_cart_url.html" type="html" module="Ayakil_HomeTry" area="adminhtml"/>
</config>

2 - hometry_cart_url.html (app/code/Ayakil/HomeTry/view/adminhtml/email/hometry_cart_url.html) file content

<!--@subject {{trans "Home Try On Cart Email!"}} @-->
<!--{{template config_path="design/email/header_template"}}-->
<p class="greeting">Dear {{var name}}</p>
<p>
Please find the Url <a href="{{var carturl}}" target="_blank"> HERE </a> to proceed with your order.</p>
<!--{{template config_path="design/email/footer_template"}}-->

3 - Controller file Email.php(Path app/code/Ayakil/HomeTry/Controller/Save.php)

....
try {
        $transport = $this->transportBuilder
            ->setTemplateIdentifier('ayakil_hometry_email_carturl_template')
            ->setTemplateOptions([
                'area' => \Magento\Framework\App\Area::AREA_ADMINHTML,
                'store' => Store::DEFAULT_STORE_ID
            ])
            ->setTemplateVars(['data' => $templateVars])
            ->setFrom([
                'email' => $this->config->getValue('trans_email/ident_support/email'),
                'name' => $this->config->getValue('trans_email/ident_support/name')
            ])
            ->addTo($email, $name)
            ->getTransport();
        $transport->sendMessage();

    } catch (MailException $mailException) {
        throw new $mailException->getMessage();
    }
}
...

I am getting the following error after save the form.

template hometry_cart_url.html not found.

I can view and load the newly created email template from admin panel Marketting->Email Template -> load templates Can anyone please help me to find my issue or suggest me a best way to do this task.

Thank you

1 Answer 1

0

I think you just defined area frontend but you setup your template to adminhtml.

Simple move the file to frontend, or change the area code to adminhtml.

1
  • i have define the are as adminhtml only, Mistakenly updated the question with frontend
    – Mujahidh
    Commented Aug 22, 2022 at 14:50

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.