0

I am doing this PHP page that have access to a Google account and than shows all emails. I've defined a header = UTF-8 and meta too, I used a lot of PHP function to convert the output to UTF but I keep getting strange icons instead of ASCII special characters. Such as ç, é or ã.

    header("Content-Type: text/html; charset: UTF-8");
    $message = imap_fetchbody($inbox,$email_number,2);
    echo $message;

What should be the output:

çççç

What I get:

=E7=E7=E7=E7

2 Answers 2

1

Use imap_qprint (see first comment on that page for an alternative solution).

Sign up to request clarification or add additional context in comments.

1 Comment

I used the first comment 's solution an that did it, thanks a lot.
0

It seems to be a known issue, regarding the first comment on the imap_fetchbody PHP doc page.

Use imap_qprint or use the commenter solution :

<?php
function ReplaceImap($txt) {
  $carimap = array("=C3=A9", "=C3=A8", "=C3=AA", "=C3=AB", "=C3=A7", "=C3=A0", "=20", "=C3=80", "=C3=89");
  $carhtml = array("é", "è", "ê", "ë", "ç", "à", "&nbsp;", "À", "É");
  $txt = str_replace($carimap, $carhtml, $txt);

  return $txt;
}

$mbox = imap_open("{imap.gmail.com:993/imap/ssl}INBOX", "login", "pass");
$no = 5; // Mail to show (mail number)

$text = imap_fetchbody($mbox, $no, 1);
$text = imap_utf8($text);
$text = ReplaceImap($text);
$text = nl2br($text);

echo $text;
?>

1 Comment

By reading the comment below I used this: $message = preg_replace("/\=([A-F][A-F0-9])/","%$1",$message); $message = urldecode($message); $message = utf8_encode($message);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.