Page 1 of 1

Form mail

Posted: Tue Apr 07, 2009 1:04 pm
by haimski
hello

i am not a php programmer and i know it might be a silly question, but i need help. i have created php form mail to send an email with details from an html form document.
the form is sending details in hebrew and i need to encode the document as utf-8.
the details is being sent to the mail but it brings the details as giberish.
I've tried many ways to encode to utf-8 that i saw on the web but it didn't work.

my php formmail attached to this messege.
how do i encode my php formail as utf-8.

thanks for any help.
contact.zip
(667 Bytes) Downloaded 11 times

Re: Form mail

Posted: Tue Apr 07, 2009 1:54 pm
by Apollo
Your content type header line (the one you add just before sending the email) should be:

Code: Select all

$headers .= 'Content-Type: text/html; charset=utf-8';
Furthermore,

1. Your way of specifying utf-8 encoding for the html page is wrong. Instead of header('content type etc..') (which sends an HTTP header, which is not what you need), just print a html meta header. For example:

Code: Select all

print('<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>');
2. Make sure the initial html page with the form uses utf-8 encoding as well. This makes sure that the form variables you receive are utf-8 encoded.

3. Use $_POST rather than $_REQUEST

4. When sending an html mail, create a full html mailbody for better compatibility:

Code: Select all

$body = "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head></body>
...your stuff here...
</body></html>";
5. What's the if (!ereg ("[äüöÄÜÖ]", $postedtext)) $postedtext = utf8_decode($postedtext); line supposed to do? (especially since you don't use $postedtext anywhere)

Re: Form mail

Posted: Wed Apr 08, 2009 1:29 am
by haimski
Thank you very much - all your tips were helpful and now it works.

i got one more small problem - the mail message title is still gibberish (only in outlook) :
i tried to change this line: $headers = "From: $fullname\r\n"; - but i didn't find the solution.

do you know what i should do?

anyway the line: if (!ereg ("[äüöÄÜÖ]", $postedtext)) $postedtext = utf8_decode($postedtext); - is a hack code for the encoding problems i had (obviously it didn't work - it should have been deleted).

once again, thanks a lot for the help.

Re: Form mail

Posted: Wed Apr 08, 2009 3:10 am
by Apollo
What do you mean with gibberish, does it seem like utf-8 content being displayed as some ansi encoding?

Does it look OK if you use English / Latin (i.e. A-Z) characters only in your message?

If you send a test message containing Hebrew characters from some gmail address (with some styling to enforce html mail) to the same outlook address, does it look OK? If yes, look into its headers and stuff, and try the same for your own emails.

Re: Form mail

Posted: Thu Apr 09, 2009 10:36 am
by haimski
i mean on the FROM line on top of the email window.

see attached image....

Re: Form mail

Posted: Thu Apr 09, 2009 12:41 pm
by Apollo
If you include those same characters in the body, and it looks OK there, then it's probably a flaw in your email program (e.g. it doesn't support non-ascii chars in the from field).

If you send a similar message (with Hebrew chars in the from part, i.e. in your name) from gmail, does that look OK? If yes, see what headers they use, and apply the same on your own emails.

Re: Form mail

Posted: Thu Apr 09, 2009 3:02 pm
by haimski
thanks man for all the help.

got it to work fine.