How to Use Special Characters in Recipients Name When Using PHP's Mail Function

How to use special characters in recipients name when using PHP's mail function

mb_encode_mimeheader should do it, just as shown in the example:

mb_internal_encoding('UTF-8');

$name = '山本';
$email = 'yamamoto@example.com';
$addr = mb_encode_mimeheader($name, 'UTF-8', 'Q') . " <$email>";

For better compatibility you should set the header Mime-Version: 1.0 so all mail clients understand you're using MIME encoding.

The final email headers should look like this:

To: =?UTF-8?Q?=E5=B0=81=E3=83=90=E3=83=BC?= <yamamoto@example.com>
Subject: =?UTF-8?Q?=E3=81=93=E3=82=93=E3=81=AB=E3=81=A1=E3=81=AF?=
Mime-Version: 1.0

Renders as:

To: 山本 <yamamoto@example.com>
Subject: こんにちは

Related: https://stackoverflow.com/a/13569317/476

php mail function with accents in name and surname

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.

php mail special characters utf8

Did you try iconv_set_encoding ?

This should work :

<?php
iconv_set_encoding("internal_encoding", "UTF-8");

$subject = "Testmail — Special Characters";
$msg = "Hi there,\n\nthis isn’t something easy.\n\nI haven’t thought that it’s that complicated!";

mail(utf8_decode($to), utf8_decode($subject), utf8_decode($msg), utf8_decode($from)."\nContent-Type: text/plain; charset=UTF-8\nContent-Transfer-Encoding: 8bit\n");?>

PHP: How to include special characters with mail()?

Try utf-8 encoding in header

like,

$headers .= "Content-Type: text/html; charset=utf-8\r\n";

See this How to convert these strange characters? (ë, Ã, ì, ù, Ã)

Sending email through PHP, pound symbol

Are you correctly setting the encoding on the email? This is done by setting

'Content-type: text/html; charset=utf-8'

in the message's headers.

Plenty of documentation here if you scroll down: http://php.net/manual/en/function.mail.php



Related Topics



Leave a reply



Submit