I'm sending email programtically bt i have a doubt "how to send email template"

this is an entry point … when i click my custom button this entry point sends a email on that account’s Primary email
email is sending successfully but now i need to send email template

Hi jrmk,

So far so good, you’ll only need to load the template, with the id maybe being posted, or fetched in some other way.

$template = \BeanFactory::getBean('EmailTemplates', $id);

Then, you can call the parse_template method on it to get the body, body_html and subject strings. You’ll need to pass an array containing the beans you want to use for your variables, maybe just the Account you already show, maybe other beans too, depending on the variables used in your template.

$beanArray = ['Accounts' => $accountId];

$subject = $template->parse_template($template->subject, $beanArray);
$body = $template->parse_template($template->body, $beanArray);
$bodyHtml = $template->parse_template($template->body_html, $beanArray);

Then you can set those fields on the mailer object which you already have:

$mail->Subject = $subject;
$mail->Body = $body;
$mail->Body_html = $bodyHtml;

And that should be all!

This sample code may help you

1 Like

there’s an error template varible do not return original value