Jump to content

Do the File Type Encoding for your doc AND the Content/charset meta tag need to be set to the same?

Whether you're a seasoned veteran or a struggling beginner, Web Radiance is the web development and web design forum for you. You'll find answers to all your HTML, CSS, SEO, and Programming needs. Pull up a chair and stay awhile.

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • This topic is locked

Do the File Type Encoding for your doc AND the Content/charset meta tag need to be set to the same? Rate Topic: -----

#21 User is offline   haku 

  • 日本語 Ninja
  • Group: Members
  • Posts: 652
  • Joined: 21-September 07
  • Gender:Male
  • Location:Yokohama, Japan

Posted 31 March 2008 - 12:25 AM

As a completely side point:

Quote

I added a "今日は World"


今日 = kyou = today. Its kind of an irregularity. Konnichiwa is always written こんにちは :D
<a href="http://www.jaypan.com" target="_blank">Jaypan</a>
<a href="http://www.dudes-japan.com" target="_blank">Dudes Japan</a>
0

#22 User is offline   Beavis 

  • W.R. Corporal
  • Group: Members
  • Posts: 167
  • Joined: 24-March 08

Posted 31 March 2008 - 07:38 AM

Haku

Thanks for the kanji tip
My verbal is much better than my written and fortunately I have a Japanese partner
who checks everything I write :)

But getting back to the task at hand, I discovered I was only having partial success.
The contact form was sending mail to my cell phone OK but its all mojibake in my web mail inbox.

I`m not using MYSQL (yet) so fortunately thats one less thing to think about.

A couple of questions.
1) In the php.ini file what is your setting for
 output_buffering
output_handler

2) Have you enabled
extension=php_mbstring.dll

3) Do your mbstring settings look like this
[mbstring]
mbstring.language = Japanese
mbstring.internal_encoding = EUC-JP
mbstring.http_input = auto
mbstring.http_output = Shift_JIS
mbstring.encoding_translation = On
mbstring.detect_order = none
mbstring.substitute_character = none;
mbstring.func_overload = 0

4) How can I check the file encoding property type of my document?
Is there a way of checking that kind of information independantly of opening in a text-editor? Which editor do you use by the way?

If you have a contact form script that I could adapt that might be an option. I assume it validates Ok?

Anyway, I really appreciate your advice so far.

This post has been edited by Beavis: 31 March 2008 - 07:39 AM

0

#23 User is offline   benbacardi 

  • Administrator
  • Group: Administrators
  • Posts: 1,140
  • Joined: 06-April 06
  • Gender:Male
  • Location:United Kingdom

Posted 31 March 2008 - 07:46 AM

If this topic is actually answered, could someone click the "The above post answers my question!" button?
0

#24 User is offline   haku 

  • 日本語 Ninja
  • Group: Members
  • Posts: 652
  • Joined: 21-September 07
  • Gender:Male
  • Location:Yokohama, Japan

Posted 31 March 2008 - 11:45 AM

Quote

1) In the php.ini file what is your setting for
 output_buffering
output_handler


Output buffering is entirely unrelated to mbstring, you don't have to worry about that.

I have this for my output_handler:

;; Set output_handler to perform multibyte conversion
output_handler	  = mb_output_handler


Quote

2) Have you enabled
extension=php_mbstring.dll


Yes. Sorry I didn't mention that before. I have this:

extension=php_mbstring.dll


You can check to see if mbstring is enabled by creating a file, and putting the following code in it:

<?php phpinfo(); ?>


(if you don't already know that). Upload the page to the server and then access it, and it will list off your mbstring settings if it is enabled.

Quote

3) Do your mbstring settings look like this
[mbstring]
mbstring.language = Japanese
mbstring.internal_encoding = EUC-JP
mbstring.http_input = auto
mbstring.http_output = Shift_JIS
mbstring.encoding_translation = On
mbstring.detect_order = none
mbstring.substitute_character = none;
mbstring.func_overload = 0


Kind of. I have a different order, and I don't have anything for a couple of those. My php.ini looks like this:
extension=php_mbstring.dll

enable-mbstring

;; Set default language to Japanese
mbstring.language = Japanese

;; HTTP input encoding translation is enabled
mbstring.encoding_translation = On

;; Set HTTP input encoding conversion to auto
mbstring.http_input   =  auto

;; Convert HTTP output to Shift_JIS
mbstring.http_output  = Shift_JIS

;; Set internal encoding to EUC-JP
mbstring.internal_encoding = EUC-JP

;; Do not print invalid characters
mbstring.substitute_character = none

;; Set output_handler to perform multibyte conversion
output_handler	  = mb_output_handler


That is all the mbstring settings that I have. Try going with that, and seeing if it works for you first (it works for me, so its a good start)

Quote

4) How can I check the file encoding property type of my document?
Is there a way of checking that kind of information independantly of opening in a text-editor? Which editor do you use by the way?


I use zend.

Once you get this stuff working, I'll help you with the mail, but its a separate issue altogether, and depends on this here working first.
<a href="http://www.jaypan.com" target="_blank">Jaypan</a>
<a href="http://www.dudes-japan.com" target="_blank">Dudes Japan</a>
0

#25 User is offline   Beavis 

  • W.R. Corporal
  • Group: Members
  • Posts: 167
  • Joined: 24-March 08

Posted 31 March 2008 - 08:50 PM

Haku

First a couple of housekeeping items.

I discovered that its possible to check the encoding details of of file by right clicking (in Firefox) and choosing "View Page Info". A handy tool.
Second, I read on a blog that PHP6 will supposedly implement UTF-8 properly so all this grief might be thing of the past one day. Lets wait and see.

Now, for the life of me I cant seem to seperate the file encoding from the charset meta tag. You say its possible.
I don`t have Zend but I`m using Dreamweaver which seems to automatically change my charset tags to match the file encoding.
In any case it SHOULD be possible to do what I want all in EUC-JP I would have thought.
I changed my php.ini settings as you described.

In any case, displaying static Japanese is not really a problem and I`m not using a MYSQL database yet, the ONLY problem I need to fix RIGHT NOW is
how to send mail from a Contact form.

If someone could tell me how, perhaps I could private message exchange my php file?
0

#26 User is offline   haku 

  • 日本語 Ninja
  • Group: Members
  • Posts: 652
  • Joined: 21-September 07
  • Gender:Male
  • Location:Yokohama, Japan

Posted 31 March 2008 - 09:40 PM

Haha, looks like dreamweaver could be causing your problems then!

I can help with this - I'm attaching a file that has JUST the meta-tag in it. The mettag is set to SJIS, but the document is saved in EUC-JP. Download this file, save it to your directory, and use it as an include inside your header like this:

<head>
<?php
	require_once("path/to/file/metatag.php");
?>
</head>


Then save your documents in EUC-JP. This *should* solve the problem if dreamweaver is automatically overwriting the metatag.

Even though you arent pulling text from a database yet, anything entered into a form is processed by PHP, and as such all these settings need to be done for it to work. That's why this stuff has to be taken care of before you start sending mails. Once you are able to get to the point where you can input Japanese in a form, and output it on the next page, then its time to start working on mail!

Edit: I couldn't upload the file for some reason, so you can download it here. Please let me know after you have downloaded it, as I will take it down.


Oh ya, I was wondering if php6 would fix this UTF issue. Although not all of these issues will disappear - output will still have to be in Shift_JIS for cell phones and the like here in Japan.
<a href="http://www.jaypan.com" target="_blank">Jaypan</a>
<a href="http://www.dudes-japan.com" target="_blank">Dudes Japan</a>
0

#27 User is offline   Beavis 

  • W.R. Corporal
  • Group: Members
  • Posts: 167
  • Joined: 24-March 08

Posted 31 March 2008 - 11:17 PM

I did as you suggested, using an "include" linked to the file on your site.
Still no joy :confused1:
Page will render but mail is not coming through.

At least I can tendatively say that the initial point of this thread has
been answered. It is possible for the encoding and charset meta tag to
differ and the page will still render ok.

I think I will refer it to my hosting company and see what they have to say.

Incidentally, which hosting company do you use?
I`m with HostMonster.
0

#28 User is offline   haku 

  • 日本語 Ninja
  • Group: Members
  • Posts: 652
  • Joined: 21-September 07
  • Gender:Male
  • Location:Yokohama, Japan

Posted 31 March 2008 - 11:43 PM

I use bluehost myself.

What do you mean by "mail is not coming through"? That sounds like it could be a different issue.
<a href="http://www.jaypan.com" target="_blank">Jaypan</a>
<a href="http://www.dudes-japan.com" target="_blank">Dudes Japan</a>
0

#29 User is offline   Beavis 

  • W.R. Corporal
  • Group: Members
  • Posts: 167
  • Joined: 24-March 08

Posted 01 April 2008 - 12:01 AM

Sorry, I meant my mail IS arriving and the english text comes out just fine but any japanese text is just a row of question marks in my webmail account.

My webmail account is "Horde Mail" provided by Hostmonster.

Originally I was forwarding mail from here to my cellphone (Softbank) and that was displaying on my phone ok but
later I checked my webmail account and found it to be mojibake.

If its possible to send files to each other I`d love to give you the "testContactUs.php" file I`m running and see
if it works with your host.
0

#30 User is offline   haku 

  • 日本語 Ninja
  • Group: Members
  • Posts: 652
  • Joined: 21-September 07
  • Gender:Male
  • Location:Yokohama, Japan

Posted 14 April 2008 - 01:53 AM

Hey there Beavis

Sorry about my slow-ass late response on this.

I'm attaching a .zip file to this post. Its a modified version of the phpmailer class. The home page for the class is here: http://phpmailer.codeworxtech.com/

and a tutorial on how to use it is here:

http://phpmailer.cod...m/tutorial.html

You should read the tutorial to find out how to install the class, and to see how it works. But when you want to send a mail, use this function:

	function japanese_mail($to, $subject, $message)
		{
			$to = mb_convert_encoding($to, "ISO-2022-JP");
			$subject = mb_convert_encoding($subject, "ISO-2022-JP");
			$message = mb_convert_encoding($message, "ISO-2022-JP");

			require_once("/path/to/class.phpmailer.php");			
			$mail = new PHPMailer();
			$mail->SetLanguage( 'ja', 'language/' );
			$mail->IsSMTP();
			$mail->Host = "mail.host.com:26";  // insert your host and port number here using this format.
			$mail->From = "no-reply@host.com"; // insert your reply address here. My host requires that this address exist for it to work, yours may or may not.
			$mail->FromName = "From Name ";
			$mail->Sender = "no-reply@mail.host.com"; // insert your reply address again here
			$mail->Mailer = "smtp";
			$mail->AddAddress($to);
			$mail->Subject = mb_encode_mimeheader($subject, "ISO-2022-JP", "B", "\n");
			$mail->Body= $message;
			$mail->SMTPAuth = "true";
			$mail->Username = "no-reply@host.com"; // add the username for your mail account here
			$mail->Password = "password"; // add the password for your mail account here
			
			if(!$mail->Send())
				{
					return false;
				}
			else
				{
					return true;
				}
		}


An example of how you could use this code is like this:

$to = to@address.com;
$subject = "the subject of the mail";
$message = "the message you want to send";
if(japanese_mail($to, $subject, $message))
{
  echo "the mail was sent";
}
else
{
  echo "mail sending failed";
}



This function sets the mail as an STMP mail so that it wont get filtered by junk mail filters. However in order for this to work, you need to send the mail from an existing mail account with the same host name from which you are sending the mail. The .rar file I included is necessary, as the Japanese wasn't working properly in the original phpmailer class, so I had to modify it a bit (don't ask what I did, because I actually can't remember!). The files are the same layout as the original phpmailer class however, so you can use them exactly the same as phpmailer class you can download from sourceforge.

Attached File(s)


This post has been edited by haku: 15 April 2008 - 08:27 AM

<a href="http://www.jaypan.com" target="_blank">Jaypan</a>
<a href="http://www.dudes-japan.com" target="_blank">Dudes Japan</a>
0

#31 User is offline   Beavis 

  • W.R. Corporal
  • Group: Members
  • Posts: 167
  • Joined: 24-March 08

Posted 14 April 2008 - 06:24 PM

View Posthaku, on Apr 14 2008, 03:53 PM, said:

Hey there Beavis

Sorry about my slow-ass late response on this.

I uploaded a .rar file here: phpmailer.rar

Its a modified version of the phpmailer class. The home page for the class is here: http://phpmailer.codeworxtech.com/

and a tutorial on how to use it is here:

http://phpmailer.cod...m/tutorial.html

You should read the tutorial to find out how to install the class, and to see how it works. But when you want to send a mail, use this function:

	function japanese_mail($to, $subject, $message)
		{
			$to = mb_convert_encoding($to, "ISO-2022-JP");
			$subject = mb_convert_encoding($subject, "ISO-2022-JP");
			$message = mb_convert_encoding($message, "ISO-2022-JP");

			require_once("/path/to/class.phpmailer.php");			
			$mail = new PHPMailer();
			$mail->SetLanguage( 'ja', 'language/' );
			$mail->IsSMTP();
			$mail->Host = "mail.host.com:26";  // insert your host and port number here using this format.
			$mail->From = "no-reply@host.com"; // insert your reply address here. My host requires that this address exist for it to work, yours may or may not.
			$mail->FromName = "From Name ";
			$mail->Sender = "no-reply@mail.host.com"; // insert your reply address again here
			$mail->Mailer = "smtp";
			$mail->AddAddress($to);
			$mail->Subject = mb_encode_mimeheader($subject, "ISO-2022-JP", "B", "\n");
			$mail->Body= $message;
			$mail->SMTPAuth = "true";
			$mail->Username = "no-reply@host.com"; // add the username for your mail account here
			$mail->Password = "password"; // add the password for your mail account here
			
			if(!$mail->Send())
				{
					return false;
				}
			else
				{
					return true;
				}
		}


An example of how you could use this code is like this:

$to = to@address.com;
$subject = "the subject of the mail";
$message = "the message you want to send";
if(japanese_mail($to, $subject, $message))
{
  echo "the mail was sent";
}
else
{
  echo "mail sending failed";
}

This function sets the mail as an STMP mail so that it wont get filtered by junk mail filters. However in order for this to work, you need to send the mail from an existing mail account with the same host name from which you are sending the mail. The .rar file I included is necessary, as the Japanese wasn't working properly in the original phpmailer class, so I had to modify it a bit (don't ask what I did, because I actually can't remember!). The files are the same layout as the original phpmailer class however, so you can use them exactly the same as phpmailer class you can download from sourceforge.


Thanks a million.
I`m this will be valuable.
I heard that Yahoo mail filters in particular have been generating a lot of false positives lately so the STMP authentication is a good idea.
Its a lot to digest so I`ll look at phpMailer in depth sometime soon.

Cheers!
0

#32 User is offline   Beavis 

  • W.R. Corporal
  • Group: Members
  • Posts: 167
  • Joined: 24-March 08

Posted 14 April 2008 - 06:26 PM

To close this post, I guess the answer is that "no" the file encoding and meta tags do not necessarily need to be the same.
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users