I'm fetching data from a mysql table (collation 'utf8_unicode_ci') and dynamically fill an email template and send the mail via PHPMailer. As of right now the special characters in the data fetched are displayed correctly. The special characters in the plain text in the mail.html are not.
As per the PHPMailer docs ... when adding $mail->CharSet = 'utf-8';
$mail = new PHPMailer();
$mail->IsHTML(true);
$mail->CharSet = 'utf-8';
then the special characters in the plain text in the mail.html are displayed correctly ... but the fetched data from the database not anymore.
What am I missing?
Update:
mysqli_set_charset($mysqli, 'utf8mb4');
... just before the select statement solved the issue.
$mail->CharSet = 'utf8_unicode_ci';
is just wrong - that's a MySQL collation, not a character set. $mail->CharSet = 'utf-8';
is correct for the email side of things, but you need to make sure that the data you're getting back from the database is actually in UTF-8 - there is plenty of documentation on how to do that, for example in this question. Also bear in mind that MySQL's standard UTF-8 charset is not complete; if you want to support things like emoji, you need to use its utf8mb4
charset.