I am sending an HTML email that contains an ü-Umlaut in it's body. I'm setting the encoding to UTF-8 in the HTML <head>, as well as in the mail header:
HTML
$body = '<html>
<head>
<title>My Title</title>
<meta charset="utf-8">
</head>
<body>
<h1>Here comes the ü-Umlaut</h1>
...
<p>Here comes an ö-Umlaut</p>
</body>
</html>';
Mail header
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=utf-8' . "\r\n";
When viewing the email on my iPhone, I see a ü instead of the ü. But when viewing the mail on my gmail account, the ü is displayed correctly. The ö is displayed correctly on both devices.
A colleague of mine correctly views the ü in his email client. But he doesn't see the ö, but a square with a question mark inside (probably something like �).
Now what's gone wrong here and how can I fix it?
Make sure your php file also forces UTF-8:
<?php
header('Content-type: text/html; charset=UTF-8');
same counts for the calling html page:
<meta http-equiv="content-type" content="text/html; charset=utf-8">
or if you use ajax:
$.ajax(
{
url: './sendemail.php',
type: 'POST',
contentType: "application/x-www-form-urlencoded; utf-8",
All participants must use the same charset. Especially the final email client:
<meta http-equiv=Content-Type content=text/html; charset=UTF-8>
Related
I'm trying to change my website from windows-1251 to utf-8, but it won't budge.
There are a ton of "solutions" to this on web, but any doesn't seem to be sufficient.
Here is what I did:
I changed the encoding of the index.html (smarty template) and index.php files to UTF-8.
I set
<html lang="ru">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
in index.html
I set
header('Content-type: text/html; charset=utf-8');
in several places in index.php
I changed
default_charset="UTF-8"
in php.ini and restarted my Apache(XAMPP) server
And still, the Chrome devtools say my page is "Content-Type: text/html; charset=windows-1251" and I see gibberish instead of Cyrillic in my browser.
What else can I do?
P.S. my index.html looks like this now:
<?php header('Content-type: text/html; charset=utf-8'); ?>
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
Тест
</body>
</html>
and I open it dirrectly via the browser: http://localhost:8080/index.html
Check this url. This might help you.
charset changing
Edit:
Try these.
Set the header before HTML tags.
<?php header('Content-type: text/html; charset=utf-8'); ?>
<!DOCTYPE html>
when you connect your script to the database you need to specify the same character set for PHP/MySQL connection.
Check
Old issue
It appeared I had a Chrome encoding extension installed, which was set to Windows-1251: https://chrome.google.com/webstore/detail/set-character-encoding/bpojelgakakmcfmjfilgdlmhefphglae
I'm trying to put html into php for emailing.The first time I tried directly entering the html into the variable (php double quotes and html in single quotes) but that resulted in an internal error. Then I used the <<< function and pasted the html insided (proper use of indentation). Now when I receive the email, i get the html file returned in plain text. How do I go from here?
$mailer->Body = <<<DEMO
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
........
</tbody>
</table>
</body>
</html>
DEMO;
if you're using plain php:
mail($to, $subject, $message, $headers);
you need to add this to the headers:
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
Currently I created simple website using include system
header.php - contains first part of HTML page (Head, meta tags, JS codes ... etc )
page.php - contains simple php code
page content
My main problem with arabic language
I have to put
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
in page.php, footer.php between <head> tags otherwise the arabic will not support correctly.
This prevents page validation because of these tags.
Is there any method to avoid this problem ?
Thanks
// Send a raw HTTP header
header ('Content-Type: text/html; charset=UTF-8');
// Declare encoding META tag, it causes browser to load the UTF-8 charset
// before displaying the page.
echo '<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />';
// Right to Left issue
echo '<body dir="rtl">';
Encode the arabic string into UTF-8 using a tool like this. (No need to change any settings - that link has the the correct settings you need).
Then use utf8_decode() to decode the string back.
Example:
<?php echo utf8_decode('your_encoded_string_goes_here'); ?>
Apart from all of the answers... Make sure your (HTML/PHP) files are saved with the right encoding utf-8
All you need is to put this
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
in a file that you include/include_once in your pages
EDIT. example:
header.html
<!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="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>my title in العربية</title>
</head>
<body>
mypage.php
<?php
include_once 'header.html';
?>
<p>
العربية
</p>
<?php
include 'foot.html';
?>
foot.html
<div>my footer</div>
</body>
</html>
1- Put this
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
2- You should also save the documents in UTF-8 not ANSI
Your headers should appear as the following:
<!DOCTYPE html>
<html lang="ar">
<head>
<meta charset="utf-8">
</head>
<body>
Save your document as utf-8
I have a contact page (contact.php) that sends a form (formsend.php) when people fill in the contact details.
The contact.php has:
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="ISO-8859-1">
Contact.php page is fine, displays my latin Portuguese characters fine (ã, é, etc).
But when I receive the email (when it uses formsend.php), I get the fields people signed up with messed up characters: João is João, etc.
On formsend.php I've tried adding:
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
and
header('Content-Type: text/html; charset=iso-8859-1');
and
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="ISO-8859-1">
as well. Nothing works.
It seems it's the formsend.php file that is failing here.
What can I do to ensure I receive properly formatted characters in the email with the user's info?
Yes you may try to switch utf-8:
and also do not forget to change header info
header('Content-Type: text/html; charset=utf-8');
but also you need to convert user inputed text to utf-8 in this case you will have no problem... I had the same problem with Armenian...
I have a PHP script called :
http://cyber-flick.com/apiMorpho.php?method=getMorphoData&word=kot
That displays some data in plain text:
Cz��� mowy: rzeczownik
Przypadek: dope�niacz
Rodzaj: şe�ski
Liczba: mnoga
As you can see in place of proper chars there are so "bushes". What i would like to do is display this in a way so that people see in browser proper UTF-8 characters.
You can encapsulate it in HMTL tags and set in meta UTF-8 encoding, but because the data received from this script will be processed further I don't want to use any HTML tags, it should be only plain text result set.
So is there a way to inform browser that this file is UTF-8 without using meta tags?
PS. File is encoded in UTF-8 and if I manually change charset encoding in my browser to UTF-8 it displays ok, but what I want to acomplish is people to not be required to do so.
header('Content-type: text/plain; charset=utf-8');
Also note that setting a header to "text/plain" will result in all html and php (in part) printing the characters on the screen as TEXT, not as HTML. So be aware of possible HTML not parsing when using text type plain.
Using:
header('Content-type: text/html; charset=utf-8');
Can return HTML and PHP as well. Not just text.
PHP, by default, always returns the following header: "Content-Type: text/html" (notice no charset), therefore you must use
<?php header('Content-type: text/plain; charset=utf-8'); ?>
You have to specify what encoding the data is. Either in meta or in headers
header('Content-Type: text/plain; charset=utf-8');
Try this way header('Content-Type: text/plain; charset=utf-8');
HTML file:
<head>
<meta charset="utf-8">
</head>
PHP file :
<?php header('Content-type: text/plain; charset=utf-8'); ?>
Html:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="x" content="xx" />
vs Php:
<?php header('Content-type: text/html; charset=ISO-8859-1'); ?>
<!DOCTYPE HTML>
<html>
<head>
<meta name="x" content="xx" />