jarvis Posted March 5, 2010 Share Posted March 5, 2010 Hi All, I've got a simple enquiry form, it then uses the following code to send an email: // 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 = "Please fill out all fields\n"; } if (!@$_REQUEST['enquiry']) { $errorsAndAlerts = "Please fill out all fields\n"; } // send email user if (!$errorsAndAlerts) { $from = $_REQUEST['email']; $to = "[email protected]"; $subject = "Quick Contact"; $message = <<<__TEXT__ Full name: {$_REQUEST['name']} Email: {$_REQUEST['email']} Enquiry: {$_REQUEST['enquiry']} Problem is it seems to add the following characters into the email: at £40,000per month What can I do to stop that? TIA jarvis Quote Link to comment https://forums.phpfreaks.com/topic/194235-remove-foreign-chars-from-enquiry-form/ Share on other sites More sharing options...
cags Posted March 5, 2010 Share Posted March 5, 2010 It's because the pound sterling sign (£) is a Unicode 2 byte character, you will need to change the charset you are using for the e-mail. If it is a HTML e-mail then something like... $headers .= "Content-Type: text/html; charset=utf8\r\n"; Quote Link to comment https://forums.phpfreaks.com/topic/194235-remove-foreign-chars-from-enquiry-form/#findComment-1022012 Share on other sites More sharing options...
jarvis Posted March 8, 2010 Author Share Posted March 8, 2010 Hi, It's a plain text email, how easy is it to conver to html? Full name: {$_REQUEST['name']} Email: {$_REQUEST['email']} Enquiry: {$_REQUEST['enquiry']} The user who sent this message had the IP address {$_SERVER['REMOTE_ADDR']}. __TEXT__; // Note: The above line must be flush left or you'll get an error // This is a PHP heredoc. See: http://ca2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc // send message $mailResult = @mail($to, $subject, $message, "From: $from"); if (!$mailResult) { die("Mail Error: $php_errormsg"); } // $errorsAndAlerts = "Thanks! We've sent your email."; $_REQUEST = array(); // clear form values } } Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/194235-remove-foreign-chars-from-enquiry-form/#findComment-1022911 Share on other sites More sharing options...
jarvis Posted March 8, 2010 Author Share Posted March 8, 2010 Ok, I've altered my code and this should be correct, however, the encoding still isn't working. Here's my code: if (!$errorsAndAlerts) { $email = $_REQUEST['email']; $to = "[email protected]"; $subject = "Quick Contact"; $body = "Full name: ". $_REQUEST['name'] ."\n\n"; $body .= "Email: ".$_REQUEST['email'] ."\n\n"; $body .= "Enquiry: ". $_REQUEST['enquiry'] ."\n\n"; $body .= "The user who sent this message had the IP address ".$_SERVER['REMOTE_ADDR']."\n\n"; $message = $body; $headers = "MIME-Version: 1.0\r\n"; #html hdr $headers .= "Content-Type: text/html; charset=utf8\r\n"; $headers .= "From: $email \r\n"; #from // send message $mailResult = @mail($to, $subject, $message, $headers); if (!$mailResult) { die("Mail Error: $php_errormsg"); } I cannot see where I'm going wrong! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/194235-remove-foreign-chars-from-enquiry-form/#findComment-1022934 Share on other sites More sharing options...
jarvis Posted March 8, 2010 Author Share Posted March 8, 2010 The page which has the enquiry form on has: <?php header('Content-type: text/html; charset=utf-8'); ?> If i alter this to iso, it fixes the email, however, it stuffs up the rest of the page. So, is there a way around this? Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/194235-remove-foreign-chars-from-enquiry-form/#findComment-1022938 Share on other sites More sharing options...
jarvis Posted March 8, 2010 Author Share Posted March 8, 2010 Solved using $textToConvert = $_REQUEST['enquiry']; $convertedText = iconv("UTF-8", "ISO-8859-1", $textToConvert); Quote Link to comment https://forums.phpfreaks.com/topic/194235-remove-foreign-chars-from-enquiry-form/#findComment-1022948 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.