Send email with tpl template

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • binhchay
    Junior Member
    • Aug 2022
    • 11

    Send email with tpl template

    I use to function like below for send email. I want to $data['body'] is tpl file but with dynamic value. Eg: <div> {{ employeecode }} </div>
    Thank you so much

    public function send($data): void
    {
    $email = $this->emailFactory->create();
    $email->setSubject($data['subject']);
    $email->setBody($data['body']);
    $email->addToAddress($data['emailTo']);
    $email->setFromAddress($data['emailFrom']);
    $email->setIsPlain();
    $this->emailSender->send($data['email']);
    }​
  • murray99
    Member
    • Jan 2017
    • 57

    #2
    When I have done this before i have used the existing Email Template functionality. Create an email template. Create an "Entity Hash" an array of the entitities to be mail merged into the message. Then emailTemplateService->parse.
    Then you can use the standard email template editor to create the message layout you want.. Also I parsing includes mustache style merges as well (perhaps someone can correct me on this). And you can make use of template helpers to add any extra wizz

    Comment

    Working...