How to Send Custom Data to Email Template

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mfonsatti
    Active Community Member
    • Jul 2018
    • 13

    How to Send Custom Data to Email Template

    Hi ,
    how can i send custom data to an email template ?
    the email is sent correctly but the data is not rendered in the template ...

    the body of the template is something like
    "Lorem ipsum dolor {customName} sit amet"

    Code:
    /* EMAIL PROCESS */
    /** @var Email $email */
    $email = $this->getEntityManager()->getEntity('Email');
    /** @var EmailTemplate $emailTpl */
    $emailTpl = $this->getEntityManager()->getEntity('EmailTemplate', $templateId);
    //$subjectTpl = $emailTpl->get("subject");
    $emailParam = [
        'subject'       => $emailTpl->get("subject"),
        'body'          => $emailTpl->get("body"),
        'isHtml'        => true,
        'from'          => $from,
        'replyTo'       => $replyTo,
        'to'            => $to,
        'customName' => $customValue
    ];
    $email->set($emailParam);
    try {
        $this->getContainer()->get("mailSender")->send($email);
    } catch (\Exception $e) {
        return [
            'response' => 'error',
            'message'  => 'EmailNotification: [' . $e->getCode() . '] ' . $e->getMessage(),
        ];
    }
    Last edited by mfonsatti; 11-21-2018, 12:10 PM.
Working...