remove odd chars from email form

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

By jarvis - March 5, 2010

Hi, Hope someone can help. I've got the following code:
// process form
if (@$_REQUEST['submitForm']) {

// error checking
$errorsAndAlerts = "";
if (!@$_REQUEST['name']) { $errorsAndAlerts = "Please fill out all fields\n"; }
if (!@$_REQUEST['email']) { $errorsAndAlerts = "Please fill out all fields\n"; }
else if(!isValidEmail(@$_REQUEST['email'])) { $errorsAndAlerts = "That email address is not valid\n"; }
if (!@$_REQUEST['enquiry']) { $errorsAndAlerts = "Please fill out all fields\n"; }

// send email user
if (!$errorsAndAlerts) {
$from = $_REQUEST['email'];
$to = "info@domain.com";
$subject = "Quick Contact";
$message = <<<__TEXT__

Full name: {$_REQUEST['name']}
Email: {$_REQUEST['email']}
Enquiry: {$_REQUEST['enquiry']}


But it gives the following in the reply
I want to appoint you at £40,000per month

I tried htmlspecialchars but maybe I used it incorrectly as couldn't get the issue resolved.

Any help would be much appreciated.

Many thanks

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);