A template language occurred when sending a message (var parsing error)
cnizzardini opened this issue · 2 comments
cnizzardini commented
Getting this error:
A template language occurred when sending a message using Template 4155010:
expression parsing error ## Access violation ## near ## {{var:url: ##
With this code:
$msg = [
'From' => [
'Email' => $this->from,
],
'To' => $this->getTo(),
'Subject' => $this->subject,
'TemplateID' => $this->template,
'TemplateLanguage' => true,
'Variables' => $this->vars,
'TemplateErrorReporting' => [
'Email' => Configure::read('email.default'),
],
'TemplateErrorDeliver' => Configure::read('debug'),
];
if (!empty($this->getBcc())) {
$msg['Bcc'] = $this->getBcc();
}
if (!empty($this->replyTo)) {
$msg['Reply-To']['Email'] = $this->bcc;
}
$response = $this->mailjet->post(Resources::$Email, ['body' => ['Messages' => [$msg]]]);
if (!$response->success()) {
Log::error(
sprintf(
"Email error in %s: %s debug: %s",
self::class,
$response->getReasonPhrase(),
json_encode(['error' => $response->getData(), 'msg' => $msg])
),
);
}
Which sends this message data:
(
[From] => Array
(
[Email] => no-reply@example.com
)
[To] => Array
(
[0] => Array
(
[Email] => test@example.com
)
)
[Subject] => Verify your email address
[TemplateID] => 4155010
[TemplateLanguage] => 1
[Variables] => Array
(
[url] => http://localhost:8080/register/confirm?email=test@example.com&hash=5edeacca4c7946298dcc3024a5f0aaffe6a4269d
)
[TemplateErrorReporting] => Array
(
[Email] => support@example.com
)
[TemplateErrorDeliver] => 1
)
My template variable is this: {{var:url:""}}
Sidenote, can we get more examples in the documentation?
cnizzardini commented
I was declaring the variable twice in my template, I guess this is not allowed. After removing one of the url vars from the template it worked....
Mailjet should return a better error if this is the case. This is odd, because if I want a clear text URL and then a linkable button I have to declare two variables with the same data...
oleksandr-mykhailenko commented
Hello @cnizzardini
Than you for you notice here, we will improve our error handling for such cases