Difference between revisions of "Email Templates"

From WHMCS Documentation

m (Custom Client Field)
(Creating Custom Templates)
 
(15 intermediate revisions by 4 users not shown)
Line 1: Line 1:
The email templates allow you to customise the messages that go out to your customers when actions occur inside WHMCS.  Every email that goes out to a customer can be customised here.
+
WHMCS's email templates allow you to customise the messages that go out to your customers when actions occur inside WHMCS.  You can customize every email that goes out to a customer here.
  
To edit an email template, go to '''Setup > Email Templates''' and click the edit icon next to the template you want to change.
+
You can access this feature at '''Configuration (<i class="fa fa-wrench" aria-hidden="true"></i>) > System Settings > Email Templates''' or, prior to WHMCS 8.0, '''Setup > Email Templates'''.
  
You can also toggle plain text vs. HTML email sending on a per email basis from the editor page.
+
== Editing Email Templates ==
 +
 
 +
To edit an email template, click the edit icon next to the template you want to change.
 +
 
 +
From the editor page, you can also toggle plain text and HTML email sending.
 +
 
 +
<div class="docs-alert-info">
 +
You can't modify the sender and subject of the email support ticket email templates. They must use a specific format for the email piping feature to import email replies into the ticket system.
 +
</div>
  
 
==Creating Custom Templates==
 
==Creating Custom Templates==
  
You can create your own email templates to serve as custom welcome emails for products or messages you send manually but frequently
+
You can create your own email templates to serve as custom welcome emails for products or messages you send manually but frequently.
  
#To do that use the '''Create New Email Template''' area at the top of the page.
+
To do this:
#You can only create email templates for the types you can manually send: General, Product, Domain & Invoice.
 
#You should use a '''unique name''' for the template so you can identify it in the send message dropdowns. Only admin users will see the name you give it.
 
#You'll be taken to the editor interface to compose the email subject and message.
 
  
Now the email will be listed in the appropriate place for sending. Please refer to the [[Messages/Emails]] page.
+
#Use the '''Create New Email Template''' area at the top of the page.
 +
#*You can only create email templates for the types you can manually send: General, Product, Domain and Invoice.
 +
#*Use a '''unique name''' for the template so you can identify it in the send message menus. Only admin users will see the name you give it.
 +
#The system will display an editor interface. Compose the email subject and message.
  
'''Note:''' The email template name "Mass Mail Template" is reserved for use by WHMCS when sending a mass mail. Any email template you create with this name will be removed after you send a mass mail, so using this name is not recommended.
+
The email should now appear in the appropriate place. For more information, see [[Messages/Emails]].
 +
 
 +
<div class="docs-alert-info">
 +
WHMCS reserves the email template name "Mass Mail Template" when sending a mass mail. The system will remove any email template you create with this name after you send a mass mail. We recommend that you don't use this name.
 +
</div>
  
 
===Adding an Attachment===
 
===Adding an Attachment===
An email template can contain attachments that will be included each time that particular email is sent to clients. Simply navigate to '''Setup > Email Templates''' and click the Edit icon next to the appropriate email template.
 
  
Then browse to the file on your computer you wish to be attached. Click the Add More link if you wish to attach more than one file. Upon clicking Save Changes the file(s) will be uploaded to your downloads directory.
+
An email template can contain attachments that the system includes each time you send that particular email to clients.
 +
 
 +
To do this:
 +
 
 +
# Click '''Edit''' next to the appropriate email template.
 +
# On your computer, browse to the file that you want to attach and select it.  
 +
# Click '''Add More''' if you wish to attach more than one file and repeat step 2.  
 +
# Click '''Save Changes'''. The system will upload the files to your downloads directory.
  
 
===Adding Headers and Footers===
 
===Adding Headers and Footers===
In version 5.0 and above it's possible to configure a universal header and footer to be used in all email templates. The header will be displayed at the top of every email template sent by the system whilst the the footer will be displayed at the bottom of every email.
+
 
These can be configured under '''Setup > General Settings > Mail tab''' and as a result the email templates are formed of the following different elements as below:
+
It's possible to configure a universal header and footer to use in all email templates. The header will display at the top of every email template that the system sends. The footer will display at the bottom of every email.
 +
 
 +
You can configure these under the '''[[Mail Tab|Mail]]''' tab at '''Configuration (<i class="fa fa-wrench" aria-hidden="true"></i>) > System Settings > General Settings''' or, prior to WHMCS 8.0, '''Setup > General Settings'''. The email templates consist of the following different elements:
  
 
  Global Email CSS Styling
 
  Global Email CSS Styling
 
 
  Global Email Header Content
 
  Global Email Header Content
 
 
  Email Template Content
 
  Email Template Content
 
 
  Global Email Signature
 
  Global Email Signature
 
 
  Global Email Footer Content
 
  Global Email Footer Content
  
 
==Disabling Templates==
 
==Disabling Templates==
  
There may be circumstances where you want to disable certain emails from sending. For example you might not want emails to go out when invoices get created, or when a product is suspended.   
+
There may be circumstances when you want to disable certain emails from sending. For example, you might not want emails to go out after invoice creation or when a product is suspended.   
  
You can do that by following these steps:
+
To do this:
  
#Edit the email template you wish to disable
+
#Edit the email template you wish to disable.
#Check the Disable tickbox in the fields at the top of the page
+
#Check the Disable checkbox in the fields at the top of the page.
#Save your changes to the email
+
#Save your changes to the email.
  
That email will now not send until re-enabled.
+
That email won't send again until you reenable it.
  
 
==Translating Email Templates==
 
==Translating Email Templates==
  
The default version under Setup > Email Templates > Edit corresponds to the language you have selected in Setup > General Settings > Localisation tab. You can translate the email templates and WHMCS will send emails in that language if the client chooses it during the order process:
+
The default language when you edit an email template corresponds to the language you have selected in the '''[[Localisation Tab|Localisation]]''' tab at '''Configuration (<i class="fa fa-wrench" aria-hidden="true"></i>) > System Settings > General Settings''' or, prior to WHMCS 8.0, '''Setup > General Settings'''.  
  
# At the bottom of the Setup > EMail Templates page select the language you wish to add from the Add dropdown menu
+
You can translate the email templates and WHMCS will send emails in that language if the client chooses it during the order process:
# Edit each email template and a second text area will appear
 
# Translate the email template into the selected language
 
  
That's all there is to it. Clients who choose that language will now receive the translated emails.
+
# Select the language you wish to add from the '''Add''' menu.
 +
# Edit each email template and a second text area will appear.
 +
# Translate the email template into the selected language.
 +
 
 +
Clients who choose that language will now receive the translated emails.
  
 
==Merge Fields==
 
==Merge Fields==
  
In email messages you can enter '''merge field''' variables which are then replaced at the time of sending automatically with the users data.
+
In email messages you can enter '''merge field''' variables, which the system replaces with the user's data when it sends the email.
  
The merge fields available in your message '''depend on what type''' of email you are sending. For example if it's an email related to a client you can include client fields only, but if it's a product related email you could include product details as well as client fields.
+
The merge fields in your message '''depend on what type''' of email you are sending. For example, if it's an email for a client, you can include client fields only, but if it's a product-related email you could include product details as well as client fields.
  
The exact list of fields you have available in any email message you are composing are listed directly below the message box with the field description and merge field code. Clicking on the description will insert the merge field at the point of your cursor in the message.
+
The exact list of fields you have available in any email message appears directly below the message box with the field description and merge field code. Clicking on the description will insert the merge field at the point of your cursor in the message.
 +
 
 +
===Addon Merge Fields===
 +
 
 +
To display the Addon name in the welcome email, use the format '''{$addon_name}'''.
 +
 
 +
This will now allow you to send the name of the Addon the client purchased in your Welcome Emails for products.
  
 
===Custom Fields===
 
===Custom Fields===
Custom fields can also be displayed in emails by way of merge fields.
+
You can also display custom fields in emails by way of merge fields.
 +
 
 
====Custom Client Field====
 
====Custom Client Field====
*To display custom client fields in the email templates, you can reference it by name using the format '''{$client_custom_field_fieldnamehere}'''.  
+
*To display custom client fields in email templates, reference them by name using the format '''{$client_custom_field_fieldnamehere}'''.  
*For fieldnamehere, you need to take your custom field name, convert the name to lowercase and remove anything other than a-z 0-9 chars. For example "VAT Number" would become "vatnumber" once the space was removed, so the merge field would be '''{$client_custom_field_vatnumber}''' in the email template.
+
*For <tt>fieldnamehere</tt>, you need to convert the custom field name to lowercase and remove anything other than a–z and 0–9. For example, "VAT Number" would become <tt>vatnumber</tt> after removing the space, so the merge field would be '''{$client_custom_field_vatnumber}''' in the email template.
  
 
====Product Custom Fields====
 
====Product Custom Fields====
*The same applies to Product custom fields, however they are referenced by '''{$service_custom_field_fieldnamehere}'''.
+
*To display product custom fields in email templates, reference them by name using the format '''{$service_custom_field_fieldnamehere}'''.
*To loop through and display all the custom fields that apply to a product, you can use a foreach loop like this:
+
*To display all the custom fields that apply to a product, you can use a <tt>foreach</tt> loop like this:
  
{foreach from=$service_custom_fields item=customfield}
+
<source lang="php">
    {$customfield.name}: {$customfield.value}
+
{foreach from=$service_custom_fields item=customfield}
{/foreach}
+
{$customfield}
 +
{/foreach}
 +
</source>
  
 
===Conditional Displays===
 
===Conditional Displays===
  
There may be cases where you want to display text in an email only if certain conditions are met. For example you might want to include specific information in a sales support ticket submission so could use the below conditional statement in the Support Ticket Opened email template:
+
You may want to display text in an email only under certain conditions. For example, you might want to include specific information in a sales support ticket submission.
 +
 
 +
To do this, use a conditional statement in the Support Ticket Opened email template. For example:
 +
 
 +
<source lang="php">{if $ticket_department eq "Sales"}The sales department is open 9-5pm Monday-Friday so you
 +
will only receive a response between these times. We thank you for your patience.{/if}
 +
</source>
 +
 
 +
More information: https://www.smarty.net/docs/en/language.function.if.tpl
 +
 
 +
===Custom PHP Logic===
  
{if $ticket_department eq "Sales"}The sales department is open 9-5pm Monday-Friday so you
+
We recommend that you avoid the <tt>{php}</tt> tags in your custom email templates for security reasons. However, if you need to use them, we recommend using the [https://developers.whmcs.com/hooks-reference/everything-else/#emailpresend EmailPreSend] hook point to create your own Smarty merge fields to run your custom PHP logic.
will only receive a response between these times. We thank you for your patience.{/if}
 
  
 
==Further Customisation==
 
==Further Customisation==
The email templates are in fact smarty template files so can take advantage of the full range of smarty syntax, just like the .tpl files which control the appearance of the system. More information can be found at [[Template Syntax]].
+
The email templates are Smarty template files. You can take advantage of the full range of Smarty syntax, just like the <tt>.tpl</tt> files, which control the appearance of the system. For more information, [https://developers.whmcs.com/themes/variables/ see our documentation].

Latest revision as of 18:17, 22 April 2022

WHMCS's email templates allow you to customise the messages that go out to your customers when actions occur inside WHMCS. You can customize every email that goes out to a customer here.

You can access this feature at Configuration () > System Settings > Email Templates or, prior to WHMCS 8.0, Setup > Email Templates.

Editing Email Templates

To edit an email template, click the edit icon next to the template you want to change.

From the editor page, you can also toggle plain text and HTML email sending.

You can't modify the sender and subject of the email support ticket email templates. They must use a specific format for the email piping feature to import email replies into the ticket system.

Creating Custom Templates

You can create your own email templates to serve as custom welcome emails for products or messages you send manually but frequently.

To do this:

  1. Use the Create New Email Template area at the top of the page.
    • You can only create email templates for the types you can manually send: General, Product, Domain and Invoice.
    • Use a unique name for the template so you can identify it in the send message menus. Only admin users will see the name you give it.
  2. The system will display an editor interface. Compose the email subject and message.

The email should now appear in the appropriate place. For more information, see Messages/Emails.

WHMCS reserves the email template name "Mass Mail Template" when sending a mass mail. The system will remove any email template you create with this name after you send a mass mail. We recommend that you don't use this name.

Adding an Attachment

An email template can contain attachments that the system includes each time you send that particular email to clients.

To do this:

  1. Click Edit next to the appropriate email template.
  2. On your computer, browse to the file that you want to attach and select it.
  3. Click Add More if you wish to attach more than one file and repeat step 2.
  4. Click Save Changes. The system will upload the files to your downloads directory.

Adding Headers and Footers

It's possible to configure a universal header and footer to use in all email templates. The header will display at the top of every email template that the system sends. The footer will display at the bottom of every email.

You can configure these under the Mail tab at Configuration () > System Settings > General Settings or, prior to WHMCS 8.0, Setup > General Settings. The email templates consist of the following different elements:

Global Email CSS Styling
Global Email Header Content
Email Template Content
Global Email Signature
Global Email Footer Content

Disabling Templates

There may be circumstances when you want to disable certain emails from sending. For example, you might not want emails to go out after invoice creation or when a product is suspended.

To do this:

  1. Edit the email template you wish to disable.
  2. Check the Disable checkbox in the fields at the top of the page.
  3. Save your changes to the email.

That email won't send again until you reenable it.

Translating Email Templates

The default language when you edit an email template corresponds to the language you have selected in the Localisation tab at Configuration () > System Settings > General Settings or, prior to WHMCS 8.0, Setup > General Settings.

You can translate the email templates and WHMCS will send emails in that language if the client chooses it during the order process:

  1. Select the language you wish to add from the Add menu.
  2. Edit each email template and a second text area will appear.
  3. Translate the email template into the selected language.

Clients who choose that language will now receive the translated emails.

Merge Fields

In email messages you can enter merge field variables, which the system replaces with the user's data when it sends the email.

The merge fields in your message depend on what type of email you are sending. For example, if it's an email for a client, you can include client fields only, but if it's a product-related email you could include product details as well as client fields.

The exact list of fields you have available in any email message appears directly below the message box with the field description and merge field code. Clicking on the description will insert the merge field at the point of your cursor in the message.

Addon Merge Fields

To display the Addon name in the welcome email, use the format {$addon_name}.

This will now allow you to send the name of the Addon the client purchased in your Welcome Emails for products.

Custom Fields

You can also display custom fields in emails by way of merge fields.

Custom Client Field

  • To display custom client fields in email templates, reference them by name using the format {$client_custom_field_fieldnamehere}.
  • For fieldnamehere, you need to convert the custom field name to lowercase and remove anything other than a–z and 0–9. For example, "VAT Number" would become vatnumber after removing the space, so the merge field would be {$client_custom_field_vatnumber} in the email template.

Product Custom Fields

  • To display product custom fields in email templates, reference them by name using the format {$service_custom_field_fieldnamehere}.
  • To display all the custom fields that apply to a product, you can use a foreach loop like this:
{foreach from=$service_custom_fields item=customfield}
{$customfield}
{/foreach}

Conditional Displays

You may want to display text in an email only under certain conditions. For example, you might want to include specific information in a sales support ticket submission.

To do this, use a conditional statement in the Support Ticket Opened email template. For example:

{if $ticket_department eq "Sales"}The sales department is open 9-5pm Monday-Friday so you
will only receive a response between these times. We thank you for your patience.{/if}

More information: https://www.smarty.net/docs/en/language.function.if.tpl

Custom PHP Logic

We recommend that you avoid the {php} tags in your custom email templates for security reasons. However, if you need to use them, we recommend using the EmailPreSend hook point to create your own Smarty merge fields to run your custom PHP logic.

Further Customisation

The email templates are Smarty template files. You can take advantage of the full range of Smarty syntax, just like the .tpl files, which control the appearance of the system. For more information, see our documentation.