Email plugin: {content} and {template} don't work

njbair

New Member
I'm using the Email plugin to notify the user and an admin when a form is submitted. If I select an article to use as a template and I leave the "Message Text" field blank, the message is received as expected. But the template is blank if I try to use the two in tandem as per the docs. For example, placing this in the message text:

<p>A user has just submitted a form. See details below.</p>
{content}


This results in a one-line email containing the first line only. The {content} placeholder is removed, but it is not replaced by the data as would be expected.

Am I doing something wrong?
 
UPDATE: I've noticed that if the Message Text field contains only the text {content} then the article template is inserted as expected.

Of course, that sort of defeats the purpose of a placeholder.
 
Okay, I've found the problem. In plugins/fabrik_form/email/email.php on line 108:
PHP:
if (!empty($messageText))
{
  $messageText = $w->parseMessageForPlaceholder($messageText, $this->data, false);
  $messageText = str_replace('{content}', $content, $messageText);
  $messageText = str_replace('{template}', $messageTemplate, $messageText);
}


This is where the placeholders are parsed. On a hunch, I figured that maybe the parseMessageForPlaceholder() method was stripping out placeholders it didn't recognize. In that case, the {template} and {content} placeholders would be gone by the time the next two lines were executed. To test this, I moved that line to the bottom of the block:
PHP:
if (!empty($messageText))
{
  $messageText = str_replace('{content}', $content, $messageText);
  $messageText = str_replace('{template}', $messageTemplate, $messageText);
  $messageText = $w->parseMessageForPlaceholder($messageText, $this->data, false);
}
This works like a charm! Not sure if it'll have any other unpleasant side-effects, but I can't imagine what those would be. I'm leaving the change for now.

This change has the added benefit that unknown placeholders in the template file or article are now stripped by the parseMessageForPlaceholder() method. Prior to this change, they would show up in the email as {whatever}, which is less graceful than a blank spot, IMO.

LMK if I should file this somewhere as a bug report.
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top