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.
- Is it a problem from PHPMailer?
- Could this be a problem from the smtp server which is "overriding" those headers?
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")."
"; $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"; } ?>
".html_entity_decode(stripslashes($author), ENT_COMPAT, $ENCODING_TYPE).""; $body.="
-----------------------------
"."FooterText"."
Tel. - Fax 06.32.16.059
I don't know why code shows html and has all those formatting problems, here you can see the pastie version:
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).