views:

56

answers:

1

I have a php page that sends mails to a specific email with the data included in the form on this page. The mail has to be sent in the native language of the website (Arabic) but when I click the submit button on the form, the mail is received half readable (Arabic language) and the other part is unreadable (Symbols). I want to know how to solve this problem and be able to send the mail to be all readable in the native language? (except for user-input symbols)

+4  A: 

Encode your message as UTF-8 (see utf8_encode()) and prepend the following header:

$header  = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";

// example
mail($to, $subject, $message, $header . $more_headers);

EDIT:

Use mb_convert_encoding() to convert your message to utf8, from whatever encoding it's currently on:

$str = mb_convert_encoding($str, 'UTF-8');
NullUserException
Based on a glance at the [documentation for `utf8_encode()`](http://php.net/manual/en/function.utf8-encode.php), I think utf8_encode will do more harm than good here. `utf8_encode()` converts Windows-1252 to UTF-8. The Windows-1252 encoding cannot represent Arabic characters, so (if my understanding is correct here) calling `utf8_encode()` guarantees that _none_ of the Arabic text is readable. Then again, `utf8_encode()` may be smarter than the documentation says it is.
Joey Adams
@Joey Thanks, fixed. Using a more reliable function
NullUserException
mb_convert_encoding() doesn`t work with arabic characters!!
sikas