-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UTF-8 html email #1010
Comments
Try putting: |
Hello @r0073rr0r , Should I put |
Headers allways goes at first lines of code in index.php |
I don't use MySQL, it's flatfile system. Let me try your solution on index.php then :) |
That header has no effect on email at all. You're already doing the only thing that PHPMailer requires for UTF-8 to work:
You will need to do the MySQL names setting too. If it's still not looking correct, it means your handling of the data is not preserving the UTF-8 encoding. If you find that static template text is correct but dynamic data from MySQL is not, then you know where the problem is. |
If you're not using MySQL it suggests that your template file's encoding is incorrect. |
Ok @Synchro, make sens, so the problem come probably from twig ? |
Perhaps - you'll probably need to tell twig it should be using UTF-8. It's quite easy to spot UTF-8 data if you hex-dump it - having it look correct isn't reliable as it might be showing you the right chars in the wrong charset. |
Hum okay 😄 Thanks for the hint, I'll make some tests |
So... I've made a var_dump on $content witch is the email template rendered by Twig with _$POST data. Here is the head of the response.
As you can see the title contain the name from _$POST data and accent are looking good. Just after that I use this rendered template ($content ) as PHPMailer Body but I still see character like Really don't understand what's happening |
Try:
According to W3 tags should be: Maybe HTML4 have problems, try changing to HTML5 instead. I dont know what can else be a problem. |
Text like Seeing those Microsoft tags in your doctype is an extremely bad sign. Steer well clear of any HTML generated by Word, it's truly terrible. That said, the doctype you're using is already HTML5. |
A little improvement with _$POST =
email look like this =
So quote and maybe some others characters still don't work. Does it help you to understand what could be the problem. PS : Thanks for your help guys and sorry if I sound newby, coding is not my job. |
About html email formating I'm using the very popular MJML framework witch is apparently the best. |
Found the solution from
to
Thanks @Synchro and @r0073rr0r to show me the path... 🚶 😃 |
Yes, that would explain the HTML entities - Twig escapes output by default. Be careful with raw option though - make sure you have validated/sanitized inputs before passing them to your template to be used unfiltered! |
@Synchro yep, everything is validated and sanitized before template is parsed. |
Hello everyone |
When you send HTML email, the message body is an HTML file; it is rendered by the client. |
Thanks for the answer. I found a solution to fix my problem. |
You saved my day |
Hello,
I'm using PHPMailer to send html emails.
I use Twig template engine to parse _POST data.
I followed your documentation to enable UTF8 but I still received email with specials characters that haven't been decoded.
Here is my mailer class:
Mailer Class based on PHPMailer
I maybe do something wrong? Any idea...
The text was updated successfully, but these errors were encountered: