Asked  7 Months ago    Answers:  5   Viewed   40 times

I have the following script:

<?php
    $subject = "Testmail — Special Characters";
    $msg = "Hi there,nnthis isn’t something easy.nnI haven’t thought that it’s that complicated!";

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

In the e-mail:

Subject: Testmail ? Special Characters

Body:

Hi there,

this isn?t something easy.

I haven?t thought that it?s that complicated!

I tried a lot of things, but I have no ideas anymore. Can you help me? Did you ever got this working?

THX!

 Answers

79

Did you try iconv_set_encoding ?

This should work :

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

$subject = "Testmail — Special Characters";
$msg = "Hi there,nnthis isn’t something easy.nnI 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-8nContent-Transfer-Encoding: 8bitn");?>
Wednesday, March 31, 2021
 
nasty
answered 7 Months ago
87

Try for subject:

$sub = '=?UTF-8?B?'.base64_encode($subject).'?=';

And then:

mail($to, $sub, $message, $headers);
Wednesday, March 31, 2021
 
akohout
answered 7 Months ago
99

for me

$test = "Nuñez";
echo $test;

shows Nuñez

You may try

$test = "Nuñez";
echo utf8_decode($test);

or

$test = utf8_encode("Nuñez");
echo utf8_decode($test);
Wednesday, March 31, 2021
 
mario
answered 7 Months ago
17

You are sending characters as Unicode, and the fields are in Unicode, but the database connection is not. Use this immediately after connecting:

SET NAMES 'utf8'
Saturday, May 29, 2021
 
ericstumper
answered 5 Months ago
79

And did you save your source file in UTF-8 encoding? If not (and I guess you didn't since that will produce the "incomplete multibyte character" error), then try that first.

Wednesday, July 28, 2021
 
VostanAzatyan
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :