Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to translate to ISO-8895-1 from UTF-8

Status
Not open for further replies.

krigbert

Programmer
Jun 2, 2005
95
NO
I have a mail form in flash that sends mails using a PHP file. The mails are to be in Norwegian, which means that there are three funny letters that need "special" encoding.

Unfortunately, using the form to send mails to Hotmail and several other places will have the mail turn up with yen-signs and what not in stead of the Æ, Å or Ø.

In other words, I need to have the PHP script change the encoding of the text it receives from the flash document (which is UTF-8) to ISO-8895-1 or whatever will work.

Or maybe there's some way to define encoding in the mail() function that makes sure the receiving mail program "gets it" and displays stuff correctly. I don't know.

My PHP now:
Code:
<?php
declare(encoding = 'ISO8895-1');
mail($toAd, $sub, $mesg, "From: $nam\nReply-To: $from\nX-Mailer: PHP/" . phpversion());
?>

illustration and webdesign
 
I don't have access to any important parts of the server, I'm afraid - is that necessary for me to solve this?

illustration and webdesign
 
Thanks, but I've always been confused by how they list those things. This is what I have now, and it doesn't even send a mail:

Code:
<?php

utf8_decode ( $subject );
utf8_decode ( $message );

mail($toAd, $subj, $mesg, "from: $nam
Reply-to: $from 
X-Mailer: PHP/" .phpversion());
?>

illustration and webdesign
 
try
Code:
<?php
$subj = utf8_decode ( $subject );
$mesg = utf8_decode ( $message );
mail($toAd, $subj, $mesg, "From: $from \r\nReply-to: $from \r\nX-Mailer: PHP/" .phpversion()."\r\n");
?>

i'd also recomment sending the mail as MIME with the right content header for the charset.
 
okay, what I have now is:

Code:
<?php

$subjec =  $subject;

$messa = '
<html>
<body style="font-family:Verdana, sans-serif; background-color:#FFFFFF; height: 100%; width: 100%;">
<p>';

$messa .= $message;
$messa .= '</p>
</body>
</html>
';


$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";

$headers .= "From: ";

$headers .= $navn;

$headers .= " <";

$headers .= $from;

$headers .= ">" . "\r\n";

mail($toAddy , $subjec, $messa, $headers);
?>

And it's working! Except the subject is still gibberish. Whenever I add the $subj = utf8_decode ( $subject ); the email won't send.

illustration and webdesign
 
You might try adding the Subject as a mail header
Code:
Subject: $subjec \r\n

then pass an empty string to php's mail() subject argument.

in the php online manual there is a user contributed scriptlet for converting utf8 to turkish. this should be easily adaptable to a scandinavian language. the link for this script is
additionally php ships with the function mb_convert_encoding

so you could also try
Code:
$subjec = mb_convert_encoding($subject,     "UTF-8","ISO-8859-1");
and then just using the mail() command normally.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top