0

I want to add controller path in Email template.I have create custom email template using programmatically.

This is my code :-

{{template config_path="design/email/header_template"}}
<table>
    <tr class="custom-gdpr">
        <p><strong>Hello {{var name}} , </strong></p>
        <p>You Are Confirom Delete Your Account in Our Store. </p>
        <p>If {{trans '<a href="Here I want to controller URL">Yes</a>'|row}} Or  {{trans '<a href="Here I want to controller URL">No</a>'|row}}</p>
        <strong>Thank you</strong>
    </tr>
</table>
{{template config_path="design/email/footer_template"}}

I want to Following link add in For Example:-

xyz.com/routername/controllername/action/customerid/encryptedid..

Please Advice me How to add Dynamic URL,

THANKS.

1

Try the following way:

use Magento\Framework\DataObject;

Now when you send transactional email, you need to pass values as DataObject Object. Ex.

'data' => new DataObject($post)

Where $post is an array.

Set the variable like:

->setTemplateVars($variables)

Check the Magento_Contact module as an example. Specially the following class:

1. vendor/magento/module-contact/Controller/Index/Post.php

private function sendEmail($post)
{
    $this->mail->send(
        $post['email'],
        ['data' => new DataObject($post)]
    );
}

2. vendor/magento/module-contact/Model/Mail.php

public function send($replyTo, array $variables)
{
    /** @see \Magento\Contact\Controller\Index\Post::validatedParams() */
    $replyToName = !empty($variables['data']['name']) ? $variables['data']['name'] : null;

    $this->inlineTranslation->suspend();
    try {
        $transport = $this->transportBuilder
            ->setTemplateIdentifier($this->contactsConfig->emailTemplate())
            ->setTemplateOptions(
                [
                    'area' => Area::AREA_FRONTEND,
                    'store' => $this->storeManager->getStore()->getId()
                ]
            )
            ->setTemplateVars($variables)
            ->setFrom($this->contactsConfig->emailSender())
            ->addTo($this->contactsConfig->emailRecipient())
            ->setReplyTo($replyTo, $replyToName)
            ->getTransport();

        $transport->sendMessage();
    } finally {
        $this->inlineTranslation->resume();
    }
}

3. vendor/magento/module-contact/view/frontend/email/submitted_form.html

{{var data.email}}
1

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.