I am using ZF2 to send emails with UTF-8 encoding:
$message->setEncoding('UTF-8');
With such test content:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Test</title>
</head>
<body bgcolor="#FFFFFF">
ĄŚĆÓłąóźćżźęĄŚĆÓłąóźćżźęĄŚĆÓłąóźćżźę
</body>
</html>
Everything is correct in modern browsers or email clients. Problem is that old OutlookExpress doesn't recognize this. Message is displayed with ISO.
What should I do to make it read properly?
I found solution. When sending html the part have its own encoding. Setting UTF-8 there makes OE read message correctly.
$html = new Mime\Part($text);
$html->type = Mime\Mime::TYPE_HTML;
$html->charset = 'utf-8';
I guess OutlookExpress is able to show UTF8. But I experienced a situation where a client had a setting to force ISO encoding instead of detection from e-mail. So check the settings of outlookExpress.
Another thing which I would do is to send email from gmail with UTF8 encoding and read it in this OutlookExpress.
- Is it showed corectly? If yes, then look on the source of the mail and check what's different from yours. If not, then problem is probably in the OutlookExpress setings.
Related
I have a problem with our E-Mail templates.
They worked fine until 2-3 days ago i have no idea what happened.
They should be utf8 encoded and get shown correctly in PHP Storm they look something like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body {
....
}
</style
</head>
<body>
<center>Content with unique characters like ěäüß</center>
</body>
</html>
But in the Email the output is completely rubbish:
Vaše zakázka etc.
I use the output buffer to get the template content and send it with PHPMailer.
There is no encoding anywhere but shouldn't be needed.
I tried utf8-encode/decode etc. It makes everything only worse.
The only thing that worked is to use tools like this http://www.percederberg.net/tools/text_converter.html
to convert the plain text into utf-8 and then the code looks like rubbish like in the mail output, but then you can manually correct every character.. that worked for some templates like in german with some äüß.... but in the Czech template you have to rewrite every single character.
Is there something that i missed? Something that i could try?
I used htmlentities() on the text parts of the templates and worked quite decent!
Example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body {
....
}
</style
</head>
<body>
<center><?php echo htmlentities("Content with unique characters like ěäüß"); ?></center>
</body>
Hope this helps someone!
I am working on a php based site where some texts are greek and some are english. Greek texts are not showing correctly. The file is saved in UTF-8. Is there anything special to do in the header of the html page to show the greek text correctly? My header is like -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Also when I submit a form containing greek text, I am using -
$firstname = mysql_real_escape_string($_POST['firstname']);
Is this okay to use "mysql_real_escape_string" here?
Try the following:
Set the collation of your database/ tables/ rows to UTF-8. UTF8_general_ci should do.
Set the connection between MySQL and PHP to UTF-8. (By executing the query SET NAMES 'utf8' after connecting or by setting the default connection encoding).
Try sending the content-type header with PHP: header("Content-Type: text/html; charset=utf-8");.
I abstracted the header from a larger set of php files for clarity. When I load it into Wampserver, the <p>é</p> appears as � on the site, despite the header calling for utf-8 charset. What is wrong in this document?
(Note that I tried to modify the encoding by replacing iso-8859-1 with utf-8, that didn't help.)
header.php:
<?php
header('Content-Type:text/html; charset=UTF-8');
echo '<?xml version="1.0" encoding="iso-8859-1"?>'
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<title>Blabla</title>
</head>
<body>
<p>é</p>
</body>
</html>
try this<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> in the head section
and also check your file encoding
You are sending two contradicting character sets, iso-8859-1 and utf-8.
If you
fix that and send only one character set, and
encode the actual file in the character set you specify (there should be a character set option in your IDE's or editor's "Save as..." dialog)
it should work.
this worked for me :
I add to the MVC COntroller : produces={"application/json;charset=utf-8"}
As explained here (PHP Include and accents (They show up as �)) php has a strange behavior processing the accents. My question is Why?
I mean: I have a simple utf-8 charset page. With this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Title</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<?php include ('file.php');?>
The included file just says: "Administración." It has no charset, just header tags (h2, h3...), and some links. Like this:
<h2>Administración</h2>
So, there is no charset conflict. Are not they supposed that the include files are just included?
The previous question was answered with some fix to the problem, but my question is Why PHP behaves this way?
to answer you new questions (from your comment):
How can I do the same thing in other
editors, how do I know the default
charset?
default-charset and charset for every single file can be set in almost every code-editor i know - where exactly depends on the editor. simply take a look into the manual/documentation of your editor for that.
I begun developing my own SIMPLE twitter client in my server (to bypass twitter.com blocking rule stablished by some dumbass at govt. office)
Please check this image so you can see the accented characters converted into weird symbol:
It is being developed with this class Twitter PHP class by Tijs Verkoyen
This is my heading code, which is utf-8. Can anyone point me to a fix?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
try using the utf8_encode() function with PHP
best is to avoid hassle if you could pass all your twitter texts(i.e. twitter API delivers JSON format too) using some sort of JSON format and pass those JSON into PHP 5 function
json_decode(jsonStr);
json_decode automatically converts to utf8 encoding which can save you from writing extra code for character encoding..