PHP Form - Email sent doesn't support characters - php

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...

Related

Content-Type charset won't change

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

HTML inside PHP is shown as plain text in email

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";

How to remove � sign from whole site in wordpress

I have uploaded wordpress site on live , then the one "�" sign is being appearing in between content , but it is fine in local. How to remove please suggest me ? I am not able fix the problem.
Example - Frédèric becomes Fr�d�ric.
Ensure that your web page also uses the UTF-8 encoding:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
If you use PHP, you can send your own headers in this way (you have to put this before any other output):
<?php header('Content-Type: text/html; charset=utf-8'); ?>

Problems with Umlaute in HTML email

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>

How to set UTF-8 encoding for a PHP file

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" />

Categories