Email Template Insert Variable

Can anyone help me figure out how to use Email Template Variables? I can not seem to find much documentation on how to use them.

I want to set up a few templates that can be used from the Leads module. So when User is on the detail view of a Lead they can simply click on the email address, select a template and click send.

That email will need the First and Last Name from the Lead values, and also the assigned user’s name. As far as I can tell, it just simple doesn’t work. It will insert the variable name, unchanged.

Is there a list of variables that can be used from particular modules? If I’m on the Contact view, $contact_first_name will work but $contact_assigned_user_name will not.

If this just doesn’t work, can you point me the in right direction to making it work myself?

If anyone has useful links or tutorials please post them. I’m all ears!

Hi. I am not sure how to answer this since I don’t use these functions much. But from your description I would say that it is correctly translating fields in the current module (Contacts) but not in related modules.

You see, the assigned user is kept just as an id in the Contacts table, but then the actual user name needs to be picked up from the Users table.

Now, I am not sure if using related fields in a Templates is supposed to work, or if it never worked. But my guess is that it should be working, but bot broken somehow.

Please have a look on GitHub to see if you can find this Issue already reported; if not, then open an Issue for this. Thanks.

https://github.com/salesagility/SuiteCRM/issues

I know I’m kind of late to the part on this one. Trying to do the same thing. In replying to the other gentleman who asked the question… If your email is related to “leads” you can only insert fields from the lead module. The rest will not work. If you relate the email to “contacts” you can only add fields form the contact record. This is how it has always worked. (it would be nice if you could relate between modules somehow!)

I also want to insert the “assigned user name” but using the “lead” record for the email only has User ID and User Name (the login name, not the full name).

I guess I could create a field in the lead to populate via workflow with the assigned user’s full name, then it would be available to pick from for the letter, but that seems like a long way around. Anyone have any simpler ideas?

1 Like

@pstevens I’ve also used the workaround you suggest in the past. It might seem overly complicated but it works and is automatic, so people quickly forget it is an issue.

I admit it would be quite nice to be able to use related fields in email templates.

When the email arrives in the test account it shows:

Dear $lead_first_name $lead_webtolead_email1 $lead_email1 $lead_name $lead_assigned_user_id $lead_last_name

  • I.e. non of the variables from the leads module are populating with the lead information?

Was this resolved?

I gave up and wrote my own parser and a bunch of replacement tokens. It was not an upgrade safe change.

Can you please try this on 7.11?

@amart817

Since, even with this problem, you are still using SuiteCRM, could you share here a full description of your code, including sources, so that all can benefit of your improvements?

Thanks!

You may also add these in gitHub so that your code is no longer upgrade unsafe!

Upgraded to 7.11, emails now won’t send at all just got a spinning wheel so can’t tell if the prior issue was fixed

I have done a lot of unsafe changes. We were in a bit of a hurry to get the things we needed added to the CRM. A lot of those changes revolved around the Email module, especially Inbound Emails. The company is trying to decide if it is best to fork from here or attempt to stay up to date with SuiteCRM. At the moment, there is too much work to be done for to focus on that.

Here is what I did for the tokens…

File: modules/Emails/Email.php
line 570ish (depending how many lines above I have added or subtracted)

You will find, this is where the parser happens:


$this->description_html = EmailTemplate::parse_template($this->description_html, $object_arr);
$this->name = EmailTemplate::parse_template($this->name, $object_arr);
$this->description = EmailTemplate::parse_template($this->description, $object_arr);

That wasn’t doing good enough for me. So I added the following below it:


require_once('custom/include/TemplateTokens.php');
$this->description_html = TemplateTokens::replace($this->description_html, $object_arr);
$this->name = TemplateTokens::replace($this->name, $object_arr);
$this->description = TemplateTokens::replace($this->description, $object_arr);

TemplateTokens is a custom class I wrote.

$object_arr already holds the related beans.

My TemplateTokens::replace method simply looks for any tokens, example: {leads_first_name}

Then it splits it at the first underscore.

So it knows it needs to get the ‘first_name’ property from the ‘leads’ bean that is in the $object_arr.

Then I have a few custom tokens like, {today_date} which replaces it with a formatted date.

I also have one that is {leads_user_fullname} which knows it needs to get the full name of the person that is assigned to the lead.

There are few others that are specific to our needs,

Version 7.11.1 is out.

I ask that you please try it and see how it goes.

If this issue here isn’t solved in 7.11.1, I need to make sure it gets fixed in the next one. The focus of the past weeks has been on email issues, and there will be at least one more sprint focused on that, so let’s make sure we get this to a satisfactory state.

So please help us test and give me your feedback, I’ll be waiting for it to determine the next steps. Thanks!

What I did was a bit of a hack and wouldn’t suggest anyone else doing it. I’m sure there is a more graceful solution. I would rather wait until I have the time to do it right before sharing. As for updating to 7.11, we are currently stuck on 7.8.8 because of all the breaking changes we made.

Is my error related to this? After upgrading to 7.11.1 fro 7.10.7 I cannot get email variable to populate in a campaign email.

Log file:
Wed Feb 13 16:44:04 2019 [13344][1][ERROR] Pop error level. Try to remove the error_reporting() function from your code.
Wed Feb 13 16:44:05 2019 [13344][1][ERROR] Unable to find relationship emails_email_templates
Wed Feb 13 16:44:05 2019 [13344][1][ERROR] Saving Email with invalid From name and/or Address. Details:
From field is not set.
From-name is not set.
From name is not set.
codes:1, 7, 10
Wed Feb 13 16:44:05 2019 [13344][1][ERROR] Unable to find relationship emails_email_templates
Wed Feb 13 16:44:06 2019 [13344][1][ERROR] Pop error level. Try to remove the error_reporting() function from your code.

(note: there are multiple “Pop error level” entries before and after)

The Campaign email template is new and simple and it looks OK. It has the From name set. Any clues? Suggestions?

TIA

@PGR, I have a selfish interest in getting the Campaign email module working so let me know if you me to help with any testing of campaign emails on 7.11.1

You can help in the following way:

  • search GitHub to see if the issue is already there

  • if not, make sure you open a new issue

  • make the issue template complete and accurate, that helps.

In my case, I think there were two different issues. The first issue, outgoing email, is now fixed thanks to Markku on Github (see other thread)

However, even with a clean 7.11.1 installation and shiny new inbound and outbound accounts (as per previous suggestions) campaign email variables are still broken, i.e. the $contact_first_name variable is not populated in the campaign email.

Log still reports this:

Tue Feb 19 11:51:03 2019 [1386][1][ERROR] Unable to find relationship emails_email_templates
Tue Feb 19 11:51:03 2019 [1386][1][ERROR] Saving Email with invalid From name and/or Address. Details:
From field is not set.
From-name is not set.
From name is not set.
codes:1, 7, 10


I’m assuming 7.11.2 may provide a fix. I’ll let you know either way.

Thanks

I don’t think 7.11.2 will include any such fix. As I wrote above, if it isn’t an open issue on Github, it won’t be visible to developers and no one will work on it…

About the email issue, I have seen your comments on GitHub but I don’t understand what is being fixed by that reinstall. Is it PHP 5 components? Is that what was causing the bug?

You’re right, it didn’t fix. Email problems persist. It might be one or multiple issues. All I know for sure is that Email variables worked in 7.10.7 and stopped working in 7.11

I will try to add to Github soon.

If I send an email directly, using a test template, the receiver gets an email with “Dear $contact_first_name,” (I’ve read this on other threads)

If I send a campaign email (using the same test template) the receiver gets an email just a blank “Dear ,”

So is that the same problem or two different problems? I have no idea.

This error in the log MAY or MAY NOT be related. I set the log to debug and this is where it seems to go fubar… (but there are too many other entries to be sure for certain):

Thu Feb 21 15:24:55 2019 [12015][1][ERROR] Saving Email with invalid From name and/or Address. Details:
From field is not set.
From-name is not set.
From address and name pair is empty.
codes:1, 7, 14
Thu Feb 21 15:24:55 2019 [12015][1][ERROR] Unable to find relationship emails_email_templates
Thu Feb 21 15:24:55 2019 [12015][1][ERROR] Unable to find relationship emails_email_templates
Thu Feb 21 15:24:55 2019 [12015][1][ERROR] Unable to find relationship emails_email_templates
Thu Feb 21 15:24:55 2019 [12015][1][ERROR] Invalid email from address or name detected before sending. Details:
From field is not set.
From-name is not set.
From address and name pair is empty.
codes:1, 7, 14

Thu Feb 21 15:24:57 2019 [12015][1][ERROR] Saving Email with invalid From name and/or Address. Details:
From field is not set.
From address is not set.
From-name is not set.
From name is not set.
From address and name pair is empty.
codes:1, 4, 7, 10, 14
Thu Feb 21 15:24:57 2019 [12015][1][ERROR] Unable to find relationship emails_email_templates
Thu Feb 21 15:24:57 2019 [12015][1][ERROR] Saving Email with invalid From name and/or Address. Details:
From field is not set.
From address is not set.
From-name is not set.
From name is not set.
From address and name pair is empty.
codes:1, 4, 7, 10, 14
Thu Feb 21 15:24:57 2019 [12015][1][ERROR] Unable to find relationship emails_email_templates
Thu Feb 21 15:24:57 2019 [12015][1][ERROR] fromUser: Conversion of from user format Y-m-d H:i failed
Thu Feb 21 15:24:57 2019 [12015][1][ERROR] Saving Email with invalid From name and/or Address. Details:
From field is not set.
From-name is not set.
From address and name pair is empty.
codes:1, 7, 14
Thu Feb 21 15:24:57 2019 [12015][1][ERROR] Unable to find relationship emails_email_templates
Thu Feb 21 15:24:57 2019 [12015][1][ERROR] Unable to find relationship emails_email_templates
Thu Feb 21 15:24:57 2019 [12015][1][ERROR] Unable to find relationship emails_email_templates
Thu Feb 21 15:24:57 2019 [12015][1][ERROR] Array
(
[0] => Unhandled email save and store as sent error: 1
[1] => 6
)

Thu Feb 21 15:24:57 2019 [12015][1][ERROR] Array
(
[0] => Unhandled non gmail sent folder hander error: 2
[1] => 100
)

@pgr, I updated the Github issue #6535 but it’s currently closed. How do I make it visible to the devs and get them to reopen it?

FYI, I didn’t open a new issue because it’s exactly as described by pstevens71, the OP.