subject of sent message gets corrupted !!

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
seme1
Forum Newbie
Posts: 8
Joined: Sun Sep 14, 2008 7:06 am

subject of sent message gets corrupted !!

Post by seme1 »

I have tried to send an email for Arabic text (with UTF-8 encoding) and the subject gets corrupted when certain Arabic characters are used.
for GMail,, these characters appear instead of some of the characters ��
Yahoo doesn't understand the subject and displays only ��������������������

I always use:
$message->setContentType("text/html");
$message->headers->setCharset('utf-8');

The header appear as follows for the subject field:
Subject: =?utf-8?B?2LHYs9in2YTYqSDZhdmGINin2YTYpdiv2KfYsdipINmE2YTY?=
=?utf-8?B?udi22Yg=?=

Please note the addition of =?utf-8?B? twice ?? why is it doing that ?
The Arabic characters that these weird looking characters replace are لع (two characters combined ,, when separate they look ل then ع )

Any hint or workaround is really appreciated.
seme1
Forum Newbie
Posts: 8
Joined: Sun Sep 14, 2008 7:06 am

Re: subject of sent message gets corrupted !!

Post by seme1 »

I think I have an idea what is happening,,
basically, the encoding of the subject line is broken into several lines. Sometimes,, it breaks one character into two lines, and hence the weird looking character � appears instead of the actual character (it appears twice by the way)..

I think this is the cause,, but I have no idea how to fix this.. Any hints/ help is really appreciated...
seme1
Forum Newbie
Posts: 8
Joined: Sun Sep 14, 2008 7:06 am

Re: subject of sent message gets corrupted !!

Post by seme1 »

After much digging, I believe the problem is caused by the substr() function... It is simply not UTF8 safe.. Please read on... http://www.phpwact.org/php/i18n/utf-8

Maybe using mb_substr would be safer ??

This should be fixed if a substitute to the php substr() is being used the native substr() is not UTF-8 safe and can damage UTF8 strings Using mb_substr() instead should fix the problem
http://uk3.php.net/manual/en/function.mb-substr.php
The encoding of subjects is where the substr() function is being used
seme1
Forum Newbie
Posts: 8
Joined: Sun Sep 14, 2008 7:06 am

Re: subject of sent message gets corrupted !!

Post by seme1 »

The patch applied here should work for swiftMailer too:

http://trac.symfony-project.org/attachm ... ding.patch
This should go to the bug tracking section,, who can I apply the above fix to SwiftMailer ??
seme1
Forum Newbie
Posts: 8
Joined: Sun Sep 14, 2008 7:06 am

Re: subject of sent message gets corrupted !!

Post by seme1 »

Is this ever going to be fixed ??
Is SwiftMailer a dead project ??
seme1
Forum Newbie
Posts: 8
Joined: Sun Sep 14, 2008 7:06 am

Re: subject of sent message gets corrupted !!

Post by seme1 »

Any chance this might be fixed sometime soon ??
andyb
Forum Newbie
Posts: 12
Joined: Tue Feb 05, 2008 3:39 am

Re: subject of sent message gets corrupted !!

Post by andyb »

If you are using UTF-8 encoding ALL PHP your code should be carefully checked for proper use. There are many non utf8 safe string functions that if used with utf-8 data will break them. Always use the mb_ equivalent functions.

As far as Swiftmailer goes, it does have a problem with passing UTF8 text in either the From: field or Subject field depending on which version you are using. Version 3.2.6 causes a problem with the From: field, and later versions fix it but then introduce a bug in the Subject field.

I have been in discussion with Chris previously about this and version 4 will fix the problem.

Oh, and it won't make a difference whether you set the encoding to Base64 or the default QP encoding.
seme1
Forum Newbie
Posts: 8
Joined: Sun Sep 14, 2008 7:06 am

Re: subject of sent message gets corrupted !!

Post by seme1 »

andyb wrote: As far as Swiftmailer goes, it does have a problem with passing UTF8 text in either the From: field or Subject field depending on which version you are using. Version 3.2.6 causes a problem with the From: field, and later versions fix it but then introduce a bug in the Subject field.

I have been in discussion with Chris previously about this and version 4 will fix the problem.

Oh, and it won't make a difference whether you set the encoding to Base64 or the default QP encoding.
This is not good news at all. It has been over 7 months since you have been promised a fix for this issue. who knows if it will ever be fixed..

Any good alternative to SwiftMailer ??? I need to deploy it in my system asap...
andyb
Forum Newbie
Posts: 12
Joined: Tue Feb 05, 2008 3:39 am

Re: subject of sent message gets corrupted !!

Post by andyb »

Yes I have been waiting months too, Chris promised version 4 would fix the problem, it has gone terribly quiet at the moment though from Chris.....
Cimmo
Forum Newbie
Posts: 1
Joined: Sat Nov 15, 2008 8:41 am

Re: subject of sent message gets corrupted !!

Post by Cimmo »

I have the same issue with my plugin: Cimy Swift SMTP for WordPress.
One chinese user provided me a real subject that got corrupted and is 100% reproducible.

I looked at the code to patch it myself, but is quite complicated do a patch that works AND that doesn't regress in some other ways.

bye
Marco
andyb
Forum Newbie
Posts: 12
Joined: Tue Feb 05, 2008 3:39 am

Re: subject of sent message gets corrupted !!

Post by andyb »

Just to let everyone know, although a supporter of Swiftmail, the lack of support recently has led me to look for other solutions due to some urgent demands.

I have come across a mail class called Nomad. Quite simply it works, where Swiftmail and PHPMailer fail, this works. I can send different languages in utf-8 including embedded images, have Russian text in From and Subject fields and it works!

I hope Chris the Developer of Swiftmail comes back online soon, but in the meantime give Nomad a try!
merijn
Forum Newbie
Posts: 11
Joined: Thu Nov 13, 2008 8:25 am

Re: subject of sent message gets corrupted !!

Post by merijn »

I created a quick fix for this. Have a look here:

viewtopic.php?f=52&t=90773&p=501692#p501692
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: subject of sent message gets corrupted !!

Post by Chris Corbyn »

This bug is fixed in version 4. Version 4 is capable of reading strings per-character rather than per-byte.
Post Reply