Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


PHP mail messing up Russian characters

Posted on 2008-11-17
Medium Priority
Last Modified: 2012-05-05
I have a client that uses PHP's mail() function to send mail from a contact form. The problem is, if a Russian user uses it, the mail that is received by the client has messed up characters instead of the Russian characters.

When he tests it on the development server it works, but when on the live server it does that.

Any ideas other than "rather use this PHP mailer script"?
Question by:DarkHill

Accepted Solution

absx earned 750 total points
ID: 22975072
I'm by no means an expert with the PHP's mail() command and prefer writing simple SMTP communication scripts with authentication support and such, but I'm quessing the character set can be messed up by either the production server's PHP configuration or the SMTP server. You could try different approaches based on whether the message is sent in text/plain or text/html.

If in text/plain, be sure to use the set_locale() command to override the server's default character set and specify the mail header:
Content-type: text/plain; charset=utf-8

If sending text/html, you could always htmlentities() the entire message to be double sure, do the previous tricks and also include a HTML meta tag
<meta http-equiv="Content-Type" content="text/html charset=utf-8" />
of course the mail header should then be:
Content-type: text/html; charset=utf-8

Hope this'll get you closer to a solution.
LVL 11

Assisted Solution

NoiS earned 750 total points
ID: 22980085
You need to convert all chars in header to an hexadecimal.
Maybe this will work for you or will give you a clue to solve your trouble

	function charsToHex($string) {
		return preg_replace("#([ãáàâäéèêëíìîïõóòôöúùûüçñ])#ie",'"=". dechex(ord("\\1"))' .'"="',$string);
$subject = "=?iso-8859-1?Q?" . charsToHex($subject) . "?=";

Open in new window


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question