Domanda

I really don't understand why when a user send an email request, the subject and the message are perfect (no escape, accents, symbols,..) it's all ok, except for the name and surname!

For example if my user full name is: Test è'ü-x-'zî in my client (MS outlook) i see: Test è'ü-x-'zî

The code to send the email is:

$subject = stripslashes( $subject );
$message  = stripslashes( $message );

$headers  = "MIME-Version: 1.0\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n";

// problem here
$headers .= "From: $user[name]<test@example.com>\nReply-to: $user[name]<$user[email]>\n\n";

@mail( $email, $subject, $message, $headers );

PS: the $user[name] is saved in the DB not in POST, in all my PHP pages i use UTF8:

<meta charset="utf-8">

header( 'Content-Type: text/html; charset=utf-8' );

mysqli_query( $con, "SET NAMES 'utf8'" ) or die( 'Error (charset)' );

how i can resolve? maybe there is a PHP function?

È stato utile?

Soluzione

Although you should ideally resolve the encoding issues elsewhere, you can use the iconv function to try converting.

iconv ( string $in_charset , string $out_charset , string $str )

could be applied to your code:

iconv("ISO-8859-1", "UTF-8", $user['name'])

The difficulty is identifying the encoding of your source, if you know this then you're good to go.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top