UTF-8 in email templates

Hello,

I use french language for my app, no problem to set phpmaker to use french language (new french.xml file), it’s working fine.
Translate the 4 html files from \template\html, OK too but i have a little problem :

When receiving activation email, for exemple (Template : register.html), the account informations are given in the correct charset but the html part of the template is sent to the wrong charset.

Here is my register.html Template :

/--------------------------------------------------------------------------------------------------/
Subject: Informations d’inscription
From:
To:
Cc:
Bcc:
Format: HTML

Cher utilisateur,

Merci pour votre inscription. Voici vos informations:

Veuillez cliquer sur le lien suivant pour activer votre compte: Activate account

N'hésitez pas à nous contacter en cas de questions supplémentaires.

Amitiés,
L'Administration du site.

/*-------------------------------------------------------------------------------------------*/ \ \ In received mail i have :

Cher utilisateur,
Merci pour votre inscription. Voici vos informations:
Nom: MARTIN
Prénom: éric
Titre:
Date de Naissance:
Adresse:
Ville:
Code Postal:
Pays:
Téléphone:
Email: xxx@free.fr
Nom d’utilisateur: éric
Veuillez cliquer sur le lien suivant pour activer votre compte: Activate account
N’h鳩tez pas à ®ous contacter en cas de questions supplé­¥ntaires.
Amiti鳬
L’Administration du site.

You can see bad chars in the 3 last lines ! ! !

How to solve this problem ?

According to source code, the template is loaded by file_get_contents(). If you use utf-8,

  • Make sure your project use utf-8 charset
  • Make sure your .html template are saved in utf-8 encoding

Hello.

Yes, my project uses the UTF-8 charset and I thought my templates were too.
Since it still didn’t work, I analyzed the Email class and found some very interesting things there.

1- public function load ($ fn, $ langId = “”).
I noticed that the function searches for the following three bytes at the start of the file: EF BB BF. I have seen on the web that files encoded in UTF-8 begin with these three bytes. so I opened my template with a hex editor and saw that these three bytes were not there.
in fact, my text editor was set to ANSI by default. After having configured it in UTF-8, I saved my template which, this time works correctly.

2- Still in this function, I noted something very interesting about the templates:
I saw somewhere on the board that to have emails in the chosen language, you had to replace the original templates with translated versions.
My research on this function allowed me to discover that it was enough to add a suffix to the name of the template once translated.

For example: I work with English and French. In the Template\html directory I kept the four original files (changepwd.html, notify.html, register.html and resetpwd.html). I then made a copy of these files which I translated into French and saved (in UTF-8 format) under the following names:
changepwd_fr.html
notify_fr.html
registe_fr.html
resetpwd_fr.html

(it also works with template names like register-fr.html)

In this way, emails will be sent automatically in the correct language, depending on the language chosen in the menu \ tools \ languages ​​of phpmaker.

If no language choosen in menu \Tools\Languages or bad language ID, English is used as long as the default templates (ex: register.html) are kept.

Best regards.

RedDog wrote:

in fact, my text editor was set to ANSI by default. After having configured it in UTF-8, I saved my template which, this time works correctly.

That is why I suggested:

Make sure your .html template are saved in utf-8 encoding

RedDog wrote:

it was enough to add a suffix to the name of the template once translated

Yes, see the topic Multi-Language Project → “Sending Email in Multi-Language” in the help file.