Is there a way to change the encoding of headers in SwiftMailer?

I am using SwiftMailer

to send emails, but I have some encoding issues with themes UTF-8

. Swiftmailer uses QPHeaderEncoder

default encoding for email headers and safeMap looks like it has some problems with some UTF-8

french characters. One item I use contains the word trouvé (found in French), and when the subject gets to the user, it shows trouv.

I would use something like NativeQPContentEncoder

that is available as a content codecs, but there is only headers Base64

and Quoted Printable

encoders.

Is there a way to fix this, maybe I am doing something wrong, so I am pasting the code that I am using here.

$message = Swift_Message::newInstance()

// set encoding in 8 bit
->setEncoder(Swift_Encoding::get8BitEncoding())

// Give the message a subject
->setSubject($subject)

// Set the From address with an associative array
->setFrom(array($from => $niceFrom))

// Set the To addresses with an associative array
->setTo(array($to)) ;

      

+3


source to share


2 answers


Check if your PHP configuration has a mbstring.func_overload

value other than 0

. If so, change it to 0

, restart the web server and try sending the message again.

mbstring.func_overload

overrides some PHP string functions and can lead to tricky UTF-8 errors.



Personally, I solved exactly this problem by disabling mbstring.func_overload

.

+2


source


First, make sure you know how your subject string is encoded. If it's not UTF-8 then utf8_encode ().



Also, make sure you set your message to Charset ('utf-8').

0


source







All Articles