-1

I have tried many solutions proposed about it, but still can't find the one that works. The email is sent succesfully but accents are in html code.

This is my code for the email content :

        $to_APPLICATION_RECEIVER = "w@z.ca";
        $from_APPLICATION_RECEIVER = "x@y.com";
        $subject_APPLICATION_RECEIVER = "Subject";
        $headers_APPLICATION_RECEIVER = 'From: "people" <x@y.com> \r\n';
        $headers_APPLICATION_RECEIVER .= 'Reply-to: x@y.com \r\n';

        //define boundary
        $semi_rand = md5(time());
        $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

        //tell header about $mime_boundary
        $headers_APPLICATION_RECEIVER .= "\nMIME-Version: 1.0\n";
        $headers_APPLICATION_RECEIVER .= "Content-Type: multipart/mixed;\n";
        $headers_APPLICATION_RECEIVER .= " boundary=\"{$mime_boundary}\"";

        //Message section
        //$message = utf8_decode($message);
        $message_hed_APPLICATION_RECEIVER ="\n\n--{$mime_boundary}\n";
        $message_hed_APPLICATION_RECEIVER .="Content-Type: text/plain; charset=\"UTF-8\"\n";
        $message_hed_APPLICATION_RECEIVER .="Content-Transfer-Encoding: 8bit\n\n" . $message . "\n\n";
        $message_hed_APPLICATION_RECEIVER .= "--{$mime_boundary}\n";

The content of $message displayed by var_dump is "sfdféèî" but the email message content I receive is : sfdf&eacute;&egrave;&icirc;. Can someone help me with that? I have tried utf8_decode() and many other propositions on forums but still it ain't working. Thanks for your help guys.

1 Answers1

1

If you view the source of the page you will see that your string actually does contain the html entities. var_dump() will have hinted at this being the case like so:

string(27) "sfdféèî"

You can convert the entities back to UTF8 with:

html_entity_decode('sfdf&eacute;&egrave;&icirc;')

Which yields:

string(10) "sfdféèî"
Sammitch
  • 30,782
  • 7
  • 50
  • 77
  • I used htmlentities() for security purposes, using html_entity_decode() won't cancel the effect of htmlentities()? – Mister Milk May 31 '18 at 18:18
  • You *say* "security purposes" but you don't seem to understand what those purposes are. You should probably read up on that more, and re-evaluate your "security" decisions. Within *this specific context* it should be fine so long as you don't decide to change the email's content-type to html at some point. – Sammitch May 31 '18 at 18:23
  • Then whatever you're using to look at that data is not set to interpret it as UTF-8. https://stackoverflow.com/questions/279170/utf-8-all-the-way-through – Sammitch May 31 '18 at 18:51