1
votes

I'm going mad, this is the code I'm using to send an e-mail utf-8 encoded, however when I receive the mail, it uses utf-8 characters but headers are set as iso-8859-1 characters.

  1. Is it a problem from PHPMailer?
  2. Could this be a problem from the smtp server which is "overriding" those headers?
  3. Any solution available?

    Connect(); $mail=new PHPMailer(); $mail->Charset = $ENCODING_TYPE; $mail->ContentType="text/html; charset=".$ENCODING_TYPE; $mail->IsSMTP(); $mail->Host=SMTP_HOST; $mail->From=SITE_MAIL; $mail->FromName=mb_convert_encoding(SITE_MAIL_NAME, $ENCODING_TYPE, "auto"); $mail->Subject=html_entity_decode(stripslashes($title), ENT_COMPAT, $ENCODING_TYPE); $body=''. stripslashes($title).''; $body.="
    ".'

    '.html_entity_decode(stripslashes($title), ENT_COMPAT, $ENCODING_TYPE).'

    '.mb_convert_encoding(stripslashes($mail_body), $ENCODING_TYPE, "auto")."
    ".html_entity_decode(stripslashes($author), ENT_COMPAT, $ENCODING_TYPE).""; $body.="



    -----------------------------
    "."FooterText"."
    Tel. - Fax 06.32.16.059

    "; $mail->IsHTML(true); $mail->MsgHTML($body); $mail->AltBody="Usare un visualizzatore di html-mail per visualizzare questa e-mail"; // $lemails=$tsql->QueryAssoc("SELECT * FROM utenti WHERE '1' AND prog_per_email='1' AND email!='' ORDER BY cognome ASC"); $lemails=Array( Array( "email" => "[email protected]", "cognome" => "Me", "nome" => "Ye" ) ); $mails_sent = 0; $mails_total = 0; foreach ($lemails as $to) { $mail->AddAddress($to["email"],$to["cognome"]." ".$to["nome"]); if ($mail->Send()) ++$mails_sent; ++$mails_total; $mail->ClearAddresses(); } return "Inoltrate ".$mails_sent." su ".$mails_total." contatti trovati"; } ?>

I don't know why code shows html and has all those formatting problems, here you can see the pastie version:

http://pastie.org/5533692

Please, note that I've written this code when I where 16 years old, and I would like to avoid a complete rewrite (well, this function can be rewritten).

1
try $mail->CharSet=$ENCODING_TYPE; instead of $mail->CharsetKasun
"what the ...", thanks, I can't believe I lost 2 hours just for this... I think it's my fault because I didn't have error reporting on. If you put it as an answer I can mark it.Francesco Belladonna
i had the same issue sometime back :) thnksKasun

1 Answers

3
votes

try $mail->CharSet=$ENCODING_TYPE; instead of $mail->Charset=$ENCODING_TYPE;