nerohj Posted October 7, 2008 Share Posted October 7, 2008 Hello all, I have a database and some fields have foreign characters in them (umlauts, haceks, etc.). I need to extract the text, and send emails with the characters in-tact. Currently this is what happens: Original text in database: Quelqu'un vous contactera aussitôt que possible. Same message when received in the email: Quelqu'un vous contactera aussitôt que possible. Here is the PHP code which extracts the text: $query = "SELECT * FROM pages WHERE confirmail_subject <> '';"; $contact =& $DBH->getRow ($query); if (PEAR::isError ($contact)) { die ($contact->getMessage() . " $query"); } if ($contact['confirmail_subject'] && $contact['confirmail_body']) { $mail_sent = mail($target_email, $contact['confirmail_subject'], $contact['confirmail_body'], "From: {$source_email}"); } Not sure what's up here, as I've never really had to pay much attention to non-english characters before now. Thanks in advance for any guidance. Cheers, Nick Quote Link to comment Share on other sites More sharing options...
tmallen Posted October 7, 2008 Share Posted October 7, 2008 You should use htmlentitites() to convert these characters. Or, you could make sure that your scripts handle all input and output in UTF8, which would be ideal. Quote Link to comment Share on other sites More sharing options...
nerohj Posted October 7, 2008 Author Share Posted October 7, 2008 Hi tmallen, Thanks for your reply. The UTF8 method sounds like the right way to go in the long run, but this is an already developed application that I have been tasked with maintaining, so right now I'm just looking for the quick fix. With that in mind, I looked into htmlentities(), however this is for escaping special characters. The idea is I've already got the correct string in the database. The special characters show up fine there. It's when I extract it from the database that the special characters get messed up, running the result of the query through htmlentities() just escaped the bad characters. $query = "SELECT * FROM pages WHERE confirmail_subject <> '';"; $contact =& $DBH->getRow ($query); if (PEAR::isError ($contact)) { die ($contact->getMessage() . " $query"); } if ($contact['confirmail_subject'] && $contact['confirmail_body']) { $mail_sent = mail($target_email, htmlentities($contact['confirmail_subject']), $contact['confirmail_body'], "From: {$source_email}"); } The email output is like so: Quelqu'un vous contactera aussitôt que possible. How can I pull the correct string from the database is it is without garbling it? Sorry if I'm missing something obvious here, as I said, completely new to dealing with special characters. Thanks, Nick Quote Link to comment Share on other sites More sharing options...
tmallen Posted October 7, 2008 Share Posted October 7, 2008 Sorry, internationalization is not my strength...you may be interested in using utf8_encode and/or utf8_decode, which converts between UTF8 chars and ISO-whatever number. Quote Link to comment Share on other sites More sharing options...
nerohj Posted October 7, 2008 Author Share Posted October 7, 2008 Hi tmalen, I looked into utf8_decode after posting my last message. That was the right way to go. Thanks a lot for your help! -Nick Quote Link to comment 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.