Email templates in Dolibarr: variables, recipient and attached PDF

Writing an invoice email template in Dolibarr: the variables that work (__REF__, amount, due date, contact), the underscore and missing-PDF traps, and how to send the email to the right contact. Tested on Dolibarr 24.0.2 and 23.0.4.

Want someone to look at your instance? Diagnosis, fixed price €90.

Versions concerned
Dolibarr 24.0.2 and 23.0.4 (tested on 04/11/2026)
What was checked (versions, tests, code read)

Tests on 04/11/2026 on fresh Dolibarr 24.0.2 and 23.0.4 installations (official Docker images, MariaDB 11.4), driven by a browser like a user: invoice template created from the templates screen, default contact for invoices, invoices really sent to a test mail server, and every email received read back (recipient, subject, text, attachment). List of variables taken from the help of the templates screen in 24.0.2. Same results on both versions. The tests used a French company and the French interface: the values shown on this page (amounts, dates, title) are in French format.

An email template saves you from retyping the same message for every invoice: “Hello Léa, here is invoice FA2611-0013 for €600, due on…”. Dolibarr replaces variables such as __REF__ with the values of the invoice. On the forums, the same questions come back: the variable that is not replaced, the wrong recipient, and the PDF that is no longer attached.

Everything below was tested on 4 November 2026 on Dolibarr 24.0.2, then replayed on 23.0.4 with the same results. Every email was really sent to a test mail server, then read back. The tests used a French company and the French interface: the screenshots are in French, and the values shown (amounts, dates, title) are in French format.

In short

Trap What happens The fix
_REF_ with a single underscore The text is sent as it is Two underscores: __REF__
Empty variable (__REF_CLIENT__ without customer ref., no contact) The variable name is sent as it is Only use it if the value always exists
__CONTACTCIVNAME__ Always empty when sending an invoice __CONTACT_TITLE_BILLING__ __CONTACT_LASTNAME_BILLING__
Template created with “Attach file” at No (value offered) The email leaves without the PDF Set “Attach file” to Yes
The customer has a billing contact “To” stays empty Choose the contact when sending

1. Create the template

The templates screen is in HomeSetupEmails, tab Email templates. For an invoice, choose the type Customer invoices. Set Default to Yes: the template will be selected by itself when you click Send email on an invoice.

Also set Attach file to Yes. The creation form offers No, and with No the email left without the invoice PDF in our tests (in 24.0.2 as in 23.0.4). Sending with Dolibarr’s original template does attach the PDF.

An invoice template with its variables, and “Attach file” set to Yes (Dolibarr 24.0.2, French interface)

2. The variables that are useful for an invoice

A variable is written with two underscores on each side, in capitals: __REF__. With a single underscore (_REF_), nothing is replaced: that was the mistake in thread 50534 of the French forum.

Values obtained in the email received, for an invoice of €500 excl. VAT (€600 incl. VAT) sent to Léa Bernard, billing contact of the customer “Boulangerie Dupont”:

Variable What it gives
__REF__ FA2611-0013 (invoice number)
__REF_CLIENT__ BC-2026-118 (customer ref. of the invoice); left as it is if the field is empty
__THIRDPARTY_NAME__ Boulangerie Dupont
__DATE_YMD__ 04/11/2026 (invoice date)
__DATE_DUE_YMD__ 04/11/2026 (payment due date)
__AMOUNT_FORMATTED__ 600,00 € (amount incl. VAT)
__AMOUNT_EXCL_TAX_FORMATTED__ 500,00 € (amount excl. VAT)
__AMOUNT_REMAIN_FORMATTED__ 600,00 € (remaining to pay)
__CONTACT_FIRSTNAME_BILLING__ Léa
__CONTACT_LASTNAME_BILLING__ Bernard
__CONTACT_TITLE_BILLING__ Madame (see the note below)
__MYCOMPANY_NAME__ the name of your company
__USER_SIGNATURE__ the signature of the user who sends (user card)

A few details, all checked in the emails received:

  • The old spelling __AMOUNT_FORMATED__ (single T), still quoted on the forums, still works in 23.0.4 and 24.0.2. The official list gives __AMOUNT_FORMATTED__.
  • Contact variables end with the role code of the contact on the invoice: _BILLING__ for the billing contact. If the invoice has no billing contact, they stay as they are in the message (“Hello __CONTACT_LASTNAME_BILLING__”): keep them for customers who have a default contact.
  • __CONTACTCIVNAME__ is always empty when you send an invoice: Dolibarr empties it before filling the message.
  • In 24, the title (Mr, Mrs…) is no longer shown on contact cards; __CONTACT_TITLE_BILLING__ therefore stays empty until it is restored (see the title field that disappeared in 24).

The full list: in the template form, click the small i next to Subject or Content. In 24.0.2 it has 145 variables, with the value of each one when it is known.

Variables are replaced when the sending form opens: you see the final text and can still edit it before sending. A variable typed by hand in that form is still replaced on sending for __REF__ or __THIRDPARTY_NAME__, but not for the contact variables: put those in the template.

The sending form: subject and text already filled in, “To” empty (Dolibarr 24.0.2, French interface)

3. Send the email to the right contact

The default contact. On the contact card, the field Default contact/address for accepts the role Invoice - Customer invoice contact. The contact is then added by itself as billing contact of every new invoice of that customer (checked in 23.0.4 and 24.0.2).

The “Default contact/address for” field on a contact card (French interface)

The “To” field. Dolibarr only ticks an address by itself when there is only one possible. A customer with no contact: their address is ticked, the email goes to them. A customer with contacts: the list offers the contacts and the customer’s address, nothing is ticked, and it is up to you to choose.

Recurring invoices (automatic sending, new in version 24) go to the billing contact of the generated invoice, otherwise to the customer’s address. Hence the point of the default contact: the contact set on an invoice before turning it into a template is not carried over (tested in 24.0.2 for an answer on the French forum).

How this was checked

On 4 November 2026, on fresh Dolibarr 24.0.2 and 23.0.4 installations (official Docker images, MariaDB 11.4, French company, French interface), driven by a browser like a user. A customer with no contact, then with an “Invoice - Customer invoice contact” contact; a default “Customer invoices” template, first with “Attach file” at No, then at Yes; invoices sent with the Send email button to a test mail server, and every email received read back: recipient, subject, text, attachment. The list of variables comes from the help of the templates screen in 24.0.2. Not tested: the templates for proposals, orders and shipments, mass sending from the invoice list, and the rich text editor (WYSIWYG).

See also

Frequently asked questions

Why is __REF__ not replaced in my Dolibarr email?

Variables are written with two underscores on each side: __REF__. With one (_REF_), Dolibarr leaves the text as it is. A variable whose value is empty, such as __REF_CLIENT__ on an invoice without a customer reference, also stays written as it is in the email.

My Dolibarr email template sends the invoice without the PDF, why?

A template created in the templates screen has the “Attach file” field set to No by default. As long as it stays at No, the email leaves without the PDF, whereas sending without a custom template attaches it. Set this field to Yes in the template.

How do I send Dolibarr invoices to a specific contact of the customer?

On the contact card, in “Default contact/address for”, choose “Invoice - Customer invoice contact”. The contact is then added to every new invoice of that customer. When sending, choose it in “To”: Dolibarr only ticks an address by itself when there is only one possible.

Dolibarremail templatemail templatesubstitution variables__REF__billing contactdefault recipientsend invoice by email

Did this guide help you?

A question about this guide, or a step that does not go as expected on your side? Write to support@dolix.fr.