How to change character encoding in phpmailer

Asked

Viewed 2,449 times

1

I don’t know anything about PHP. Nothing. Zero. Niente. It turns out that a form on a page of a simple HTML client is processed by Phpmailer.

It works like a beauty, even if I have no idea how.

Only it DELIVERS messages at destination with characters with another encoding. There is no way someone could write the name JOÃO in the field and I could receive it like this. Joao arrives.

I don’t know where this changes, if there’s a way or if I’m screwed.

Somebody give me a hand?

Someone?

Plis?

2 answers

5

Helio, use:

<?php

// Inclui o arquivo class.phpmailer.php localizado na pasta phpmailer
require_once("phpmailer/class.phpmailer.php");

// Inicia a classe PHPMailer
$mail = new PHPMailer();

// (...) codigos

// Define os dados técnicos da Mensagem
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//$mail->IsHTML(true); // Define que o e-mail será enviado como HTML
$mail->CharSet = 'iso-8859-1'; // Charset da mensagem (opcional)

If $mail->CharSet = 'iso-8859-1'; not working, try to $mail->CharSet = 'UTF-8';!

If it still doesn’t work, see if your file .php was saved with the correct charset. See in the example below, the Notepad++ changing the document charset .php:

inserir a descrição da imagem aqui

  • Show. It’s a shame I can’t vote. I have no reputation. But oh, thanks!

  • Heheh imagines! The community will see the commentary. Hug!

1

An easy solution is to use the PHP function utf8_decode(). Assuming you are sending the message via a variable with the name "message" and a field called "message", it would look like this:

$mensagem = utf8_decode($_POST['mensagem']);

You can find more information in the documentation:

http://php.net/manual/en/function.utf8-decode.php

Browser other questions tagged

You are not signed in. Login or sign up in order to post.