Hello,

I am using a php page ( HTML "UTF-8" charset ), which sends an AJAX request as "UTF-8", to a mailer page which simply sends a message to a certain Hotmail account... the problem is that the message cannot be read, it contains weird symbols, but everything is set to "UTF-8" and i tried to give a php header charset as "UTF-8" to the mailer page itself, but nothing worked...

Any help ?

    Why are setting it as UTF-8?

    Do you have to use that charset or is it one you just chose?

    If you must set the charset have you tried other standard character sets?

    Lastly it may help if we saw the code, for it, as it could be something as simple as a typo causing the hassle.

      I am using UTF-8 because of Arabic language... I have to...

      I tried other charsets including "arabic-1256" but nothing seems to work...

      the codes are :

      Contact.php

      <html>
      <head>
      
      <script src="include/http_request.js"></script>
      
      <script type="text/javascript">
      <!--
      
      function send_message()
      {
      var xmlhttp = getxmlobject();
      if ( xmlhttp == null )
        {
        alert("Your Browser Does Not Support HTTP Requests");
        return;
        }
      var name = document.getElementById("name").value;
      var location = document.getElementById("location").value;
      var email = document.getElementById("email").value;
      var email_regex = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-Z0-9]{2,4}$/;
      var subject = document.getElementById("subject").value;
      var message = document.getElementById("message").value;
      if ( name.length == 0 || location.length == 0 ||  email.length == 0 || subject.length == 0 || message.length == 0 )
        {
        alert("كل الØ*قول ازامية");
        return;
        }
      
      if ( !email.match(email_regex) )
        {
        alert("البريد الالكتروني غير صالØ*");
        document.getElementById("email").focus();
        return;
        }
      
      var url = "include/mailer.php";
      var ran = Math.random();
      var dt = "name=" + escape(name) + "&location=" + escape(location) + "&email=" + escape(email) + "&subject=" + escape(subject) + "&message=" + escape(message) + "&ran=" + ran;
      xmlhttp.open("POST",url,true);
      xmlhttp.onreadystatechange = function statechange()
        {
        if ( xmlhttp.readyState == 4 || xmlhttp.readyState == "complete" )
          {
          document.getElementById("name").value = "";
          document.getElementById("location").value = "";
          document.getElementById("email").value = "";
          document.getElementById("subject").value = "";
          document.getElementById("message").value = "";
      
      document.getElementById("name").disabled = true;
      document.getElementById("location").disabled = true;
      document.getElementById("email").disabled = true;
      document.getElementById("subject").disabled = true;
      document.getElementById("message").disabled = true;
      document.getElementById("reset").disabled = true;
      document.getElementById("send").disabled = true;
      
      alert(xmlhttp.responseText);
      }
        }
      xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
      xmlhttp.send(dt);
      }
      
      //-->
      
      </script>
      
      <style>
      <!-- 
      body {scrollbar-face-color: #5C7B98; scrollbar-shadow-color: #5C7B98; scrollbar-highlight-color: #FFFFFF; scrollbar-3dlight-color: #5C7B98; scrollbar-darkshadow-color: #5C7B98; scrollbar-track-color: #E2D6C0; scrollbar-arrow-color: #FFFFFF;}
      }
      // -->
      </style>
      
      <link rel="stylesheet" type="text/css" href="include/style.css" />
      <title>:: الموقع الرسمي لعلماء مدينة صور ::</title>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      </head>
      <body bgcolor="#FFFFFF" background="images/texture.jpg" link="#5C7B98" vlink="#5C7B98" alink="#5C7B98">
      <a href="index.php"><img src="images/index.gif" border="0" width="1002" height="203" alt=""></a>
      <table width="996" border="0" cellpadding="0" cellspacing="0" mm:layoutgroup="true" height="575">
        <tr> 
          <td height="10" valign="top" colspan="4">
          <p align="center"><font size="5"><b>
      
      <?php
      
      require("include/connection.php");
      
      $sql = "SELECT * FROM tbl_marquees WHERE mid=10";
      
      mysql_query("SET NAMES 'UTF8'"); 
      mysql_query('SET CHARACTER SET UTF8'); 
      
      if ( $res = mysql_query($sql, $conn) )
        {
        $result = mysql_fetch_array($res);
        }
      
      ?>
      
      <marquee direction="right" onmouseover="this.stop()" onmouseout="this.start()"><?php echo $result["mtxt"]; ?></marquee></font></b></td></td>
        </tr>
        <tr> 
          <td valign="top" height="442" colspan="3">
      
      <div id="div" style="overflow: auto; width: 820; height: 425; border: 2 solid; text-align: center;  padding: 12px"><br />
      
      <form method="">
      <table>
      <tr>
      <td align="center"><font size="4"><b>الأسم</b></font></td>
      <td><input type="text" dir="rtl" id="name" name="name" maxlength="50" /></td>
      </tr>
      
      <tr><td align="center"><font size="4"><b>العنوان</b></font></td><td align="right"><input type="text" dir="rtl" id="location" name="location" maxlength="50" /></td></tr>
      
      <tr><td align="center"width="120"><font size="4"><b>البريد الالكتروني</b></font></td><td align="right"><input type="text" id="email" name="email" maxlength="50" /></td></tr>
      
      <tr><td align="center"><font size="4"><b>الموضوع</b></font></td><td align="right"><input type="text" dir="rtl" id="subject" name="subject" maxlength="50" /></td></tr>
      
      <tr><td align="center"><font size="4"><b>الرسالة</b></font></td><td><textarea dir="rtl" cols="35" rows="7" id="message" name="message"></textarea></td></tr>
      
      <tr><td>&nbsp;</td></tr>
      
      <tr><td></td><td align="center"><input type="reset" id="reset" name="reset" value="مسØ*" />&nbsp;<input type="button" id="send" name="send" onclick="send_message()" value="أرسل" /></td></tr>
      
      </table>
      </form>
      
      </div>
      
      
      </td>
          <td valign="top" width="166" height="450">
          <p align="center">
          <img border="0" src="images/menu.gif" width="150" height="49">
            <p align="center"> <a href="structure.php"><img border="0" src="images/Button%20(1).gif" width="145" height="29"></a><a href="members.php"><img border="0" src="images/Button%20(2).gif" width="145" height="29"></a><a href="articles.php"><img border="0" src="images/Button%20(3).gif" width="145" height="29"></a><a href="audio.php"><img border="0" src="images/Button%20(4).gif" width="145" height="29"></a><a href="speechs.php"><img border="0" src="images/Button%20(5).gif" width="145" height="29"></a><a href="news.php"><img border="0" src="images/Button%20(6).gif" width="145" height="29"></a><a href="queries.php"><img border="0" src="images/Button%20(7).gif" width="145" height="29"></a><a href="library.php"><img border="0" src="images/Button%20(9).gif" width="145" height="29"></a><a href="forums/" target="_blank"><img border="0" src="images/Button%20(10).gif" width="145" height="29"></a><a href="contact.php"><img border="0" src="images/Button%20(8).gif" width="145" height="29"></a><a href="sitemap.php"><img border="0" src="images/Button%20(11).gif" width="145" height="29"></a> 
            <p align="center">
          <img border="0" src="images/menu%20end.gif" width="150" height="11"></td>
        </tr>
      
        <tr> 
          <td height="0" colspan="4" valign="top">
          <img border="0" src="images/low.gif" width="993" height="30">
      
      <div align="center"><font face="arial" size="2"><b>Copyright &copy; 2009 – All Rights Reserved</b></font></div><br />
      <div align="center"><font size="2">Designed By <b><a href="mailto:xxxxx@hotmail.com">Bilal Baroud</a></b> – Developed By <b><a href="mailto:xxxxx@hotmail.com">Raed Abou Saleh</a></b></font></div>
      </table>
      </body>
      </html>

      Please don't worry about the weird characters, they are displayed fine...

      mailer.php

      <?php
      
      require("connection.php");
      
      $sql = mysql_query("SELECT * FROM tbl_contact");
      
      if ( $sql && $conn )
        {
        $result = mysql_fetch_array($sql);
        $to = strtolower($result["email"]);
        }
      else
        {
        $to = "xxxxx@hotmail.com";
        }
      
      $from = ucfirst($_POST["name"]);
      $subject = ucwords($_POST["subject"]);
      $message = "Name : ". $from ."\nLocation : ". ucwords($_POST["location"]) ."\ne-mail : ". $to . "\n\nMessage : ". ucfirst($_POST["message"]);
      $headers = $from;
      
      $mail = mail($to, $subject, $message, $headers);
      
      if ( $mail )
        {
        echo "تم ارسال الرسالة بنجاØ*";
        }
      else
        {
        echo "لم تنجØ* Ù…Ø*اولة ارسال الرسالة";
        }
      
      ?>

      So the message is being successfuly sent, but as weird and not arabic characters...

      Thanks for helping,
      Raed

        Try setting the charset in the mail() header. I am guessing PHP has different charset as its default for the mail() function

        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        

        Copied that from mail() on php.net

          didn't work, actually even if I select any encoding from right click => encoding... the characters remain the same, even if I switch from arabic to english to turkish!! the point is that the characters remain the same, so i guess it's not a mailer encoding problem, any help ?

            Please don't worry about the weird characters, they are displayed fine...

            That statement got me thinking. If you see them as odd looking characters, like I am, it means your browser is not set to UTF-8. When I set my browser to UTF-8 I can see arabic letters.

            Which raises the question of how you are viewing the email. So if your viewing the email in your browser make sure it is set to UTF-8. And if it is an email program like Thunderbird or Outlook you may also need to change it to view UTF-8.

            After that if you are still having issues I would only guess something is happening on the server side.

              After that if you are still having issues I would only guess something is happening on the server side.

              yes you are right, I am still having an issue, because as I said, I tried all the available encoding when reading the email ( by changing them when right clicking and selecting encoding... )

              I meant by those weird characters, that they are displayed weird in the source code only and not in the output... so it is a weird problem... everything is set to UTF-8 and still, weird characters such as "%u0631"

              Any help would really be appreciated...

                Write a Reply...