2

When I visit my page I get a blank display and the following message:

"The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must be declared in the document or in the transfer protocol."

Here's the relevant code:

<?php 
$errors = array();
$missing = array();
//check if the form has been submitted
if (isset($_POST['send'])) 
{
//email processing script
$to = '$_POST['email']';
$subject = 'Your Quote';
$expected = array('email',);
$required = array('email');
$headers .= 'Content-Type: text/plain; charset=utf-8';
require('./includes/processmail.inc.php');
if ($mailSent) {
header('Location: http://www.dailyspiro.com/email.php');
exit;
}
}       
?>

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <meta content="utf-8" http-equiv="encoding"> 
NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
  • possible duplicate of [The character encoding of the HTML document was not declared](http://stackoverflow.com/questions/11996257/the-character-encoding-of-the-html-document-was-not-declared), [Character encoding not declared in html document](http://stackoverflow.com/questions/11633162/character-encoding-not-declared-in-html-document) – sachleen Apr 28 '13 at 04:30
  • What browser did you get this error from? – Plummer Apr 28 '13 at 04:54
  • 1) Make your code more readable. It will help you track down errors. 2) The error you're getting doesn't have anything to do with your PHP code, but the character encoding you set in your meta. 3) Is there more code? If no, you didn't tell the page to show anything, with your PHP or your HTML. – Plummer Apr 28 '13 at 04:32

2 Answers2

2

Use following PHP header at the top of the PHP Code

header('Content-type: text/html; charset=utf-8');

ie.

<?php 
header('Content-type: text/html; charset=utf-8');
$errors = array();
$missing = array();
//check if the form has been submitted
if (isset($_POST['send'])) 
{
//email processing script
$to = '$_POST['email']';
Ritesh Kumar Gupta
  • 5,055
  • 7
  • 45
  • 71
-5

Instead of using a meta tag to declare encoding, try using a standard doctype like

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
half-fast
  • 302
  • 1
  • 7
  • 1
    ` ` *is* a standard doctype - it's the doctype to be used from HTML5 forward. – Tieson T. Apr 28 '13 at 04:39
  • Of course, but what I mean is why not try something that's been a standard for how many years now? It only makes sense to go to something more widely used and accepted first when having problems. – half-fast Apr 28 '13 at 04:41
  • Youre just the kind of guy to downvote a completely helpful answer, lol. – half-fast Apr 28 '13 at 04:43
  • Not a helpful answer at all. HTML5 valid doctype declaration already exists. Not to mention the problem is with character encoding and not !DOCTYPE declaration. Do u even HTML, BRO?! – Plummer Apr 28 '13 at 04:51
  • Wow, what a comment. Of course it already exists ... tell me, is it actually 100% working, and a full standard yet, BRO?! No, the answer is no. – half-fast Apr 28 '13 at 04:59