Encoding issues with PHP contact form
I'm newbie to PHP, HTML and to programming at all. I'm trying to create a contact form with PHP and HTML. Everything is working fine, and i'm able to get the e-mails. Except of one thing, If i'm trying to fill the form with another language, In my case it's hebrew, The mail i'm getting is with gibrish. I saved the html file with the UTF-8 encoding, and i added the meta code. checked my outlook encoding and checked the mails i'm getting with a webinteface and it's still gibrish.
开发者_如何学运维Any ideas?
First of all, try to "Echo" the content of the email to the browser instead of sending it out.
- If it displays correctly, you are fine on the website part.
- If the text is coming from a POST or GET form, you might need to convert it with htmlspecialchars_decode(), see http://www.php.net/manual/en/function.htmlspecialchars-decode.php
Then you can take care about the format of the email.
If you are sending email, you need to set the proper headers for the email just as you do for the website. For UTF-8, you would do:
$headers = "From: ExRobot <robot@example.com>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=utf-8\r\n";
$headers .="Content-Transfer-Encoding: 8bit";
If your subject also might include foreign languages you can set it to
"=?utf-8?B?".base64_encode($subject)."?="
If this does not help, post a complete sample email here as you get it. this will help a lot to understand what is wrong.
精彩评论