Charset information in contact_form?

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
mpop

Charset information in contact_form?

Post by mpop »

Hello everybody,
Not sure whether I should post this here, but here I go anyway...

I've had a bit of trouble with the contact_form script from 1.0.2. I'm doing a French website, so I hacked my way through plugin.contact_form.php to have French text and labels, to add information to the body of the message, etc. But I've had problems with character encoding, and these are not related to my (poor and clumsy) changes, since they happen with the original script and with Version: 1.4 (20061010) of the script as well.

My website is using UTF-8 (http headers ok, meta tag ok), and the messages sent are UTF-8 as well... but the e-mails sent are not declared as utf-8.

TEST 1:
sending a message with
- ascii characters only in the title ;
- non-ascii characters in the message's body.
Result : both gmail and Thunderbird reckon the message is in iso-8859-1

TEST 2:
sending a message with
- non-ascii characters in the title ;
- non-ascii characters in the message's body.
Result : both gmail and Thunderbird reckon the message is in UTF-8

Which means that the message is not sent with any charset information. Ouch. I checked it with Thunderbird (taking a look at the headers of the received e-mails) : no charset information.

So I had to hack the original script to add charset information. I did it that way (not sure that's how you do it for e-mail, but I tried it and it seems to work fine) :

Code: Select all

	//$extra .= "Content-Type: text/plain\r\n";
	$extra .= "Content-Type: text/plain; charset=UTF-8\r\n";
I commented out the original line.

Well, it's a quick and dirty hack, but it seems to work fine.


I'm no developer, so I can't code something more reliable (fetching the actual encoding from the cms config, or maybe from the page's http headers / server information?). But I thought that pointing this out could be useful. :)


Have a nice day. :)
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

Re: Charset information in contact_form?

Post by Dee »

Changed in SVN to use utf-8 or config['default_encoding']) if it is set. (changes will be in 1.0.3).
Download the latest version of contact_form here.

Thanks for reporting this.
Last edited by Anonymous on Sun Dec 10, 2006 2:05 pm, edited 1 time in total.
mpop

Re: Charset information in contact_form?

Post by mpop »

Dee wrote: Thanks for reporting this.
I'm glad to be able to contribute, even if it's only for the little details. :)
zebulon
Forum Members
Forum Members
Posts: 37
Joined: Sun Aug 27, 2006 8:21 pm

Re: Charset information in contact_form?

Post by zebulon »

mpop wrote:
Dee wrote: Thanks for reporting this.
I'm glad to be able to contribute, even if it's only for the little details. :)
Thanks, folks, for all the input. I did all of the above but I'm still encountering problems with the subject line.
After upgrading to Maui and upgrading the funktion.contact_form.php to 1.4 it still replaces german Umlaute (äöüß...) to "XX"

Could it be, that the command "cfSanitize" (lines 57 - 59) is responsible for this?
... NO! I just tried it and cut it out; the result is the same: within 'name' and 'subject' all these special characters are replaced by "XX".

Any idea and any help is greatly apprechiated!

cheers,
zebulon
zebulon
Forum Members
Forum Members
Posts: 37
Joined: Sun Aug 27, 2006 8:21 pm

Re: Charset information in contact_form?

Post by zebulon »

cyberman wrote: Have you read this :)?

http://forum.cmsmadesimple.org/index.ph ... l#msg26006
No. But now I did and tried what is desribed there. So, line #57 for instance now reads:

if (!empty($_POST['name'])) $name = utf8_decode(cfSanitize($_POST['name']));

I tested this again - nothing changed, sadly. Still, the "XX" stay in 'subject' and 'from' whereas the 'message' shows them correctly!

Odd... I'm looking forward to your input which I really apprechiate and will search for contact_form and utf-8 etc. I also promise to post my solution, once it works!  ;D

cheers,
zebulon
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

Re: Charset information in contact_form?

Post by Dee »

I tested the current version of contact_form.php with those characters (äöüß) in the subject and message and it seems to work fine overhere.

If PHP runs in safe mode the fourth parameter ($extra) to PHP's mail function, containing the From field (sender name) and Content-Type (now including charset) is ignored.
Last edited by Anonymous on Tue Dec 12, 2006 3:22 pm, edited 1 time in total.
zebulon
Forum Members
Forum Members
Posts: 37
Joined: Sun Aug 27, 2006 8:21 pm

Re: Charset information in contact_form?

Post by zebulon »

Dee wrote: I tested the current version of contact_form.php with those characters (äöüß) in the subject and message and it seems to work fine overhere.
That's what I did, too, just before and once again. No go ... same old XXX  ???
If PHP runs in safe mode the fourth parameter ($extra) to PHP's mail function, containing the From field (sender name) and Content-Type (now including charset) is ignored.
I checkes this: nope, safe-mode is off.

I also tried an older version of the german translation version of that function which worked before: nothing new, sadly...
Oh, and I forgot: I tried mail, SMTP and sendmail => ... you guessed it; same XXX all over the subject and 'From'...

I think it's something with the update to MAUI responsible for this.

cheers,
zebulon
Heidi

Re: Charset information in contact_form?

Post by Heidi »

Dee wrote: Changed in SVN to use utf-8 or config['default_encoding']) if it is set. (changes will be in 1.0.3).
Download the latest version of contact_form here.

Thanks for reporting this.
What excactly did you change?
I've done quite a translator-job on this file, and would prefer to copy/paste just the changes.
I have version 1.3. of function.contact_form.php.

ÆØÅ are working fine in the subject, but messing up completely in the message text.

Thank you in advance.
Last edited by Heidi on Wed Jan 17, 2007 8:55 pm, edited 1 time in total.
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm
Location: the Netherlands

Re: Charset information in contact_form?

Post by Dee »

These are the changes made to contact_form.php since cmsmadesimple-1.0.2 was released.

That particular change was the last one, changeset 3565.

Regards,
D
Heidi

Re: Charset information in contact_form?

Post by Heidi »

Thanks Dee!
You even solved my problem with pretty URLs  :)
Post Reply

Return to “Developers Discussion”