法语字符在PHP邮件中无法正确显示 [英] French characters not displaying correctly in PHP mail

查看:116
本文介绍了法语字符在PHP邮件中无法正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的PHP邮件形式,但无论如何,如果语言用法语口音书写,我似乎无法让字符正确显示。



我使用的例句是:


Bonjour,ceci est un message de testenvoyéavec PHP pour analyzer si
oui ou non la mise en forme est correcte ou fausse。 Les personnages ne
devraientêtrerendus demanièreaccéecommeprévudans le
lexiquefrançais。


但它来了out as:


Bonjour,ceci est un message de testenvoyéavec PHP pour analyzer si
oui ou non la mise en forme est correcte ou fausse。 Lesㄧages ne ne ne neÃÃÃÃÃÃÃÃb b b b b b b b b b b b b b b b b b b b b b b b>>>>>>> $ b

正如你所看到的,一旦收到电子邮件,字符的字符就被弄坏了。



我正在处理我的消息变量:

  $ fieldenquiry = utf8_encode($ _ POST ['fieldenquiry']); 

然后,我发送如下:

  $ cc =example@example.com; 
$ subject =网站查询;

$ message ='< html>< body>';
$ message。=< p>< strong>查询< / strong>< br /> 。 nl2br($ fieldenquiry)。 < / P> 中;
$ message。=< / body>< / html>;

$ headers =From:。 $ fieldemail。 \r\\\
;
$ headers。=Cc:。 $ cc。 \r\\\
;
$ headers。=回覆:。 $ fieldemail。 \r\\\
;
$ headers。=MIME-Version:1.0\r\\\
;
$ headers。=Content-Type:text / html; charset = UTF-8\r\\\
;

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

我不是一个PHP开发人员。该表单的工作原理是它发送等等,但我无法弄清楚为什么这些角色搞乱了。我编码POST变量,我发送一个UTF-8字符集的HTML格式。



帮助和指导赞赏。



Michael。



编辑:



解决方案

如果有人需要类似的帮助,我想到了:



我更改了这一行:

  $ fieldenquiry = utf8_encode($ _ POST ['fieldenquiry ]); 

为此:

  $ fieldenquiry = utf8_encode(htmlentities($ _ POST ['fieldenquiry]],ENT_QUOTES,UTF-8)); 

我使用参数中指定的UTF-8的htmlentities()函数。



这完全解决了问题。希望它帮助某人。


I have a basic PHP mail form, but whatever I do, I cannot seem to get the characters to display correctly once sent, if the language is written with French accents.

The example sentence I am using is:

Bonjour, ceci est un message de test envoyé avec PHP pour analyser si oui ou non la mise en forme est correcte ou fausse. Les personnages ne devraient être rendus de manière appropriée comme prévu dans le lexique français.

But it comes out as:

Bonjour, ceci est un message de test envoyé avec PHP pour analyser si oui ou non la mise en forme est correcte ou fausse. Les personnages ne devraient être rendus de manière appropriée comme prévu dans le lexique français.

As you can see, the characters with accents are screwed up, once they are received in the email.

I am processing my message variable as such:

$fieldenquiry = utf8_encode($_POST['fieldenquiry']);

I am then, sending it like so:

$cc = "example@example.com";
$subject = "Website Enquiry";

$message = '<html><body>';
$message .= "<p><strong>Enquiry</strong><br />" . nl2br($fieldenquiry) . "</p>";
$message .= "</body></html>";

$headers = "From: " . $fieldemail . "\r\n";
$headers .= "Cc: " . $cc . "\r\n";
$headers .= "Reply-To: ". $fieldemail . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";

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

I'm not a PHP developer by any means. The form works in the sense that it sends etc, but I cannot figure out why the characters mess up. I am encoding the POST variable and I am sending the HTML format with a UTF-8 charset.

Help and guidance appreciated.

Michael.

EDIT:

I figured this out. See my answer below.

解决方案

I figured it out if anyone is in need of a similar piece of help:

I changed this line:

$fieldenquiry = utf8_encode($_POST['fieldenquiry']);

To this:

$fieldenquiry = utf8_encode(htmlentities($_POST['fieldenquiry'], ENT_QUOTES, "UTF-8"));

I use the htmlentities() function with UTF-8 specified in the arguments.

This fixed the issue completely. Hope it helps someone.

这篇关于法语字符在PHP邮件中无法正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆