0

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?

ipel
  • 1,326
  • 1
  • 18
  • 43
  • possible duplicate of [How to use special characters in recipients name when using PHP's mail function](http://stackoverflow.com/questions/7669668/how-to-use-special-characters-in-recipients-name-when-using-phps-mail-function), [send mail from php - charset encoding](http://stackoverflow.com/questions/7879784/send-mail-from-php-charset-encoding/7883771#7883771) – deceze Sep 02 '13 at 15:18
  • yes it's a duplicate, i searched but found nothing. Now that i know this is a duplicate what should i do? – ipel Sep 05 '13 at 14:41

1 Answers1

1

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.

Ross
  • 3,022
  • 1
  • 17
  • 13