How to change the character encoding in phpmailer

1

I do not handle anything from PHP. Anything. Zero. Niente. It happens that a form on a page of a simple HTML client is rendered by PHPmailer.

It works great, even though I have no idea how.

Only it DELIVER messages on the destination with characters with another encoding. There is no way for someone to write in the field name JOHN and I receive it like that. Joao arrives.

I do not know where this changes, whether or not I get screwed.

Does anyone give me a help?

Someone?

Plis?

    
asked by anonymous 01.07.2015 / 05:06

2 answers

3

Helium , 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'; does not work, try $mail->CharSet = 'UTF-8'; !

If it still does not work, see if your .php file was saved with the correct charset. See the example below, Notepad++ by changing the document charset .php :

    
01.07.2015 / 05:10
1

A very easy solution is to use the utf8_decode () PHP function. 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:

link

    
13.03.2017 / 22:40