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 and prepend the following header:utf8_encode()
)
$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
2010-08-19 13:54:37
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
2010-08-19 14:08:08
@Joey Thanks, fixed. Using a more reliable function
NullUserException
2010-08-19 14:15:02
mb_convert_encoding() doesn`t work with arabic characters!!
sikas
2010-10-30 15:22:06