Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift_Mailer + symfony UTF-8

I have an issue with Swift_Mailer in Symfony. I am sending e-mail messages in French which contain a lot of "à é è" characters. At first when i tried sending these characters came out fine in my email-client, but in my colleague's email-client they didn't.

So I put the text for the mail through a utf8_encode function and tried again. Now it is vica-versa. It shows fine in my email-client, but screwed up in my colleague's.

What is the best way to solve these e-mail UTF-8 issues with Swift_Mailer in Symfony?

like image 772
Pino Avatar asked Jan 20 '12 15:01

Pino


1 Answers

Use $message->toString(); to see if your e-mail is well formatted, meaning everything is UTF-8 or uses the proper European ISO charset iso-8859-15. You can use setCharset to tell it what you're actually using.

The character set of the message (and it’s MIME parts) is set with the setCharset() method. You can also change the global default of UTF-8 by working with the Swift_Preferences class.

Swift Mailer will default to the UTF-8 character set unless otherwise overridden. UTF-8 will work in most instances since it includes all of the standard US keyboard characters in addition to most international characters.

It is absolutely vital however that you know what character set your message (or it’s MIME parts) are written in otherwise your message may be received completely garbled.

http://swiftmailer.org/docs/messages.html#setting-the-character-set

like image 137
greut Avatar answered Sep 22 '22 23:09

greut