PHP E-Mail Encoding

PHP E-Mail Encoding?

As far as I know PHP does not support UTF-8 as default encoding for its strings. You need to use the relevant encoding/handling functions for the encoding you would prefer.

Also add a Content-Type:text/html;charset=utf-8 to your email headers so the email clients will display the characters correctly (or replace with your encoding of choice).

PHP send email message coding in utf-8

mail($to,utf8_decode($subject),utf8_decode($message),utf8_decode($headers));

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 email sent with issues on subject chars in Outlook only

The only reliable way to send e-mail is using plain 7 bit ASCII so you need to encode strings properly when you want to use anything else. In your case, [WEBSITE] áccent – tésts should be encoded as (e.g.) =?windows-1252?B?W1dFQlNJVEVdIOFjY2VudCCWIHTpc3Rz?=, where the string splits as:

=?windows-1252?B?W1dFQlNJVEVdIOFjY2VudCCWIHTpc3Rz?=
^ ^ ^
| | |
Charset | Data
|
Base64

Check:

echo base64_decode('W1dFQlNJVEVdIOFjY2VudCCWIHTpc3Rz'); // [WEBSITE] áccent – tésts

This is just an example of one of the possible ways to encode non-ASCII strings.

When sending e-mail, there are many little details like this that need attention. That's why sooner or later you end up using a proper e-mail package like Swift Mailer or PHPMailer.



Related Topics



Leave a reply



Submit