remove odd chars from email form

4 posts by 2 authors in: Forums > CMS Builder
Last Post: March 8, 2010   (RSS)

Re: [jarvis] remove odd chars from email form

By jarvis - March 8, 2010

Hi,
I think i'm making headway on this. The page which the form resides on has:
<?php header('Content-type: text/html; charset=utf-8'); ?> If I alter this to:
<?php header('Content-type: text/html; charset=iso-8859-1'); ?>
It fixes the issue, however, it breaks the page as it displays odd characters. I've also rewritten the email code to use HTML emails, this way I can encode it in the headers. However, I think the header type on the page is over writing it.

Any ideas?
Many thanks

Re: [jarvis] remove odd chars from email form

By jarvis - March 8, 2010

Solved using $textToConvert = $_REQUEST['enquiry'];
$convertedText = iconv("UTF-8", "ISO-8859-1", $textToConvert);

Re: [jarvis] remove odd chars from email form

By Dave - March 8, 2010

Hi Jarvis,

Nice work, glad you got it working! :)

I wouldn't change it if it's working, but another way to do it is to set the charset for the email to be utf-8 as well. Here's the code we do that with for the CMSB password reminder:

$headers = "Content-Type: text/plain; charset=UTF-8\n";
$headers .= "From: {$SETTINGS['adminEmail']}\n";
$mailResult = @mail($to, $subject, $message, $headers);


Alternatively, we have a new mail function we're working on in the latest version which is at the bottom of /lib/common.php and works like this:

sendMessage(array(
'from' => "from@example.com",
'to' => "to@example.com",
'subject' => "Enter subject here, supports utf-8 content",
'text' => "Text message content",
));


It automatically encodes content as utf-8, supports text and/or html messages, and even file attachments.

If it's working now I'd just leave it as-is, but if you run into more troubles in future you might give that a try. Just called sendMessage with the above code rather than mail.

Hope that helps!
Dave Edis - Senior Developer
interactivetools.com