Page 1 of 1
hebrew email gets wierd display when sent
Posted: Sun Oct 04, 2009 3:51 am
by gil.r21
Hi all
I have a problem with sending mail.
In my site I have a simple contact me form and I am handling it thru AJAX
the problem is that the data is in hebrew
it is being sent to the handle-file and being emailed to me but unfortunatly
instead of Hebrew I am getting URL encoded data - like this:
%u05D2%u05D9%u05DC
my email function looks like this:
Code: Select all
function send_mail($to,$username,$user_email,$text){
$text=str_replace ("\n","<br/>",$text);
$subject="New message from a student";
$message=<<<EOM
<div dir="rtl" align="right">
<b><u>name</u></b><br/>$username<br/>
<b><u>email</u></b><br/>$user_email<br/>
<b><u>contents</u></b><br/>$text
</div>
EOM;
$header = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
$header.='FROM: PO.BOX@mysite.co.il'."\r\n".'reply-to:'.$user_email."\r\n";
mail($to,$subject,$message,$header) or die("can't email");
}
I have tried using urldecode function on the variables but with no luck
please help
Re: hebrew email gets wierd display when sent
Posted: Sun Oct 04, 2009 5:32 am
by Darhazer
Actually you have to base64 encode your message, and to add a Content-encoding: base64 header. This is the correct way to send non-latin characters. If your headers contain non-latin characters, they also have to be encoded.
Additionally, make sure that ajax operates in UTF-8. Best, post that part of the code
Re: hebrew email gets wierd display when sent
Posted: Sun Oct 04, 2009 8:52 am
by gil.r21
Hi
Ajax is operating in utf-8 both the file that's sending the request was saved in utf-8 format
and also the webpage containing the form is displayed in utf-8
I am using joomla and made a module of it - meaning my module displays the form and sends an ajax request to another file.
the thing is that it used to work and I have no Idea what did I do afterwards that made it not work.
I am posting the ajax code maybe the problem is there
actually I think that the actual text is being transffered url encoded
that's also what the ajax header is set to
but when I do urldecode
it doesn't work
btw I tried using base64 now and it doesn't work because the data is getting there encoded and for some reson I cant decode it
Code: Select all
<script type="text/javascript">
<!--
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = stopRKey;
function xmlhttpPost(strURL) {
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
updatepage(self.xmlHttpReq.responseText);
}
}
self.xmlHttpReq.send(getquerystring());
}
function getquerystring() {
document.getElementById("get_ajax").innerHTML = "<img src='modules/mod_contactform/ajax-loader.gif' align='center'/>";
document.getElementById("get_ajax").style.display ="block";
var form = document.forms['contact'];
var email = form.email.value;
var user_email = form.user_email.value;
var sname = form.sname.value;
var content = form.content.value;
qstr = 'email=' + escape(email); // NOTE: no '?' before querystring
qstr += '&user_email=' + escape(user_email);
qstr += '&sname=' + escape(sname);
qstr += '&content=' + escape(content);
return qstr;
}
function updatepage(str){
if(str=="100"){var reply="?????? ????? ??????.";document.forms['contact'].reset();}
else if(str=="200"){var reply="?????? ?????: ???? ???? ?????.";}
else if(str=="300"){var reply="?????? ?????: ??? ???? ????????.";}
else if(str=="400"){var reply="?????? ?????: ????? ???? ???????? ????? ??????.";}
else if(str=="500"){var reply="???? ????? ?????? ?????? - ???? ??????.";}
else {var reply=str;}
document.getElementById("get_ajax").innerHTML = reply;
document.getElementById("get_ajax").style.display ="block";
}
-->
</script></div>
thanks for the help
Re: hebrew email gets wierd display when sent
Posted: Sun Oct 04, 2009 9:33 am
by gil.r21
ok solved it
the problem was that I ran all my post variables thru JS:escape()
that's it thanks lol