0

I have created the custom module for customer registration request including an email function also. email function is working fine.

I have customized the email template using Marketing -> Communication ->Newsletter Template -> Add New Template.

When customer registration request the email template is not getting from the customized one.its getting from the module.

What i want to do to use the customized email template?

file -> email_templates.xml

<?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="registration_request_template" label="Customer Registration Request" file="registration_request.html" type="html" module="E25media_CustomerRegistration" area="frontend"/>

Controller email

$full_name = $first_name." ".$last_name;
        $templateOptions = array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $this->_storeManager->getStore()->getId());
        $templateVars = array(
                    'store' => $this->_storeManager->getStore(),
                    'full_name' => $full_name,
                    'email' => $email,
                    'phone' => $phone,
                    'company' => $company,
                    'position' => $position,
                    'vessel' => $vessel
                );
        $from = array('email' => $email, 'name' => $full_name);
        $this->_inlineTranslation->suspend();

        $to = array('[email protected]');
        $to = $this->getCustomerSupportEmail();
        $transport = $this->_transportBuilder->setTemplateIdentifier('registration_request_template')
            ->setTemplateOptions($templateOptions)
            ->setTemplateVars($templateVars)
            ->setFrom($from)
            ->addTo($to)
            ->getTransport();
        $transport->sendMessage();
        $this->_inlineTranslation->resume();
2
  • Share your code. Commented Oct 15, 2018 at 6:14
  • @AnshuMishra i have updated the email xml and controller email section
    – Mujahidh
    Commented Oct 15, 2018 at 6:30

2 Answers 2

0

You need to add file from the file structure. Please add the template in view-> frontend->email folder and then modify the email_template.xml

File->email_template.xml

    <template id="registration_request_template" label="Email Form" file="registration_request_template.html" type="html" module="companyname_modulename" area="frontend"/>

Please clear cache and run indexing and check! Hope it helps!

1
  • Have u defined it in email_template.xml because the code you shared doenst have it
    – surbhi agr
    Commented Oct 15, 2018 at 7:14
0

You have provided static email template id in your code as follows:

setTemplateIdentifier('registration_request_template')

instead of static email id, you have can create an option in admin to select the email template, something as follows: Code in your module's etc/adminhtml/system.xml

------

<section id="custom_section" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
    -----
    <group id="custom_fields_masks" translate="label" type="text" sortOrder="50" showInDefault="1">
        <label>Custom label</label>
        <field id="custom_email_template" translate="label" type="select" sortOrder="20" showInDefault="1" canRestore="1">
            <label>Email Template</label>
            <source_model>Magento\Config\Model\Config\Source\Email\Template</source_model>
        </field>
    </group>
    -------

Then you can call the template id using the following code:

$this->scopeConfig->getValue(
            <field path>,
            ScopeInterface::SCOPE_STORE,
            <store_id>
        );

All the above codes are sample you need to modify according to your requirement.

2
  • thanks for your answer.can you please explain little bit more regarding this?if possible with some sample codes
    – Mujahidh
    Commented Oct 15, 2018 at 7:47
  • @Mujahidh basically, that whole point is that, you need to provide the email template id of the template that you have created in admin in the code setTemplateIdentifier('registration_request_template') Commented Oct 15, 2018 at 9:06

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.