I know I am missing something here, but I simply can't figure it out after searching the forum and PHP manual.

Basically, I have a web form using mail () function that users send mail with.

Now I would like to use strtr function to replace some accented characters, and don't know how to write it to use multiple character pairs and $_POST.

Example:

if($_POST['vrsta'] == "Informacije")
		{		
		  $sendto = "some@mail.com";
		  $vrsta = $_POST['vrsta'];
		  $ime = $_POST['ime'];
		  $tvrtka = $_POST['tvrtka'];
		  $telefon = $_POST['telefon'];
		  $email  = $_POST['email'];
		  $upit = $_POST['upit'];
		  $mail_header="Return-Path:some@mail.com\n
Content-Transfer-Encoding: base64\n
Content-Type: text/plain; charset=iso-8859-2";

      mail($sendto, "$vrsta", "Upit: $upit\n\n
Poslao: $ime\n\nTvrtka: $tvrtka\n\n
Telefon: $telefon",  "From: $email\n$mail_header");

Now what I would need to do here is insert strtr function into $ime, $tvrtka and $upit variables so all accented characters user enters are replaced with ordinary Cc,Zz,Ss, Dd characters.

I have tried with a single pair

$ime = strtr($_POST['ime'], "è", "c");

but obviously it's wrong - no replacement performed.

Can you please give me a hand here, how to produce the wanted with multiple character pairs and $_POST so it would work? I just can't seem to get it 🙁

    you are using the wrong function. you want str_replace(), not strstr().

    $ime = str_replace('è', 'c', $_POST['ime']);
    
      $ime = str_replace($_POST['ime'], "è", "c");

      Tried this, replacement took place, and stripped all other letters from the $ime variable.

      So instead of example. "car" I got "c".

      However, I believe I should fiddle with properly formatted array to perform this. Geez, I am already banging my head to a table...

      Anyway, after getting this to work, I even might be able to replace accented characters with proper encoding entities to really display accented characters properly at some point.

      Now I've seen a solution from some Czech guy using the same codepage. I didn't get it to work because I don't understand his numerous explanations, but I'll post his code as an idea:

      
      function CZMail($to, $subj, $text, $headers = "")
      {
        // pøevedení z windows-1250 do iso-8859-2 (pokud je potøeba)	
        $text = StrTr($text, 
        				"\x8A\x8D\x8E\x9A\x9D\x9E", 
        	"\xA9\xAB\xAE\xB9\xBB\xBE");
        // pøekódování do Base64  
      $text = Base64_Encode($text); // pøidání hlavièek $headers .= "MIME-Version: 1.0\n". "Content-Type: text/plain; charset=\"iso-8859-2\"\n". "Content-Transfer-Encoding: base64\n"; // odeslání e-mailu
      Mail($to, $subj, $text, $headers); }

      He further says 'You can send mail with diacritics now', but all I can understand from the example is he actually replaces win-1250 characters with iso-8859-2.

      Can someone help me here? My hair is in the air 🙁

        i think you need to re-read my example code:

        you are using this:

        $ime = str_replace($_POST['ime'], "è", "c");

        my example was this:

        $ime = str_replace('è', 'c', $_POST['ime']);

          Erm, first I did just as you instructed me:

          $ime = str_replace('č', 'c', $_POST['ime']);

          Entered čača into formfield

          Mail returned:

          èaèa - no replacement, I get the same without str_replace

          Then I tried from PHP manual - obviously wrong 🙁

            èaèa - no replacement, I get the same without str_replace

            of course there was no replacement, you are searching for the literal string:

            č

            which is not present in your formfield.

              $ime = str_replace('č', 'c', $_POST['ime']);

              Actually I typed this character: č but when I enlose the line into PHP tags here, it outputs UTF-8 numeric entity.

              Mail output:

              èaèa

              Tried adding MIME:

              R˜_º+£ÎëO¢ÉZ§6ói;ë¶FŠ­Š*¡7¥yú'ãž9ëŽ9ãž9 - this is the full mail output, the whole mail is garbaged.

              I am beginning to think my server doesn't support iso-8859-2 or UTF-8 in SMTP. Is it possible?

                Write a Reply...