无法在 php 邮件中显示法语口音

发布于 2024-12-13 11:01:40 字数 489 浏览 5 评论 0原文

我有以下 php 脚本根据返回的参数发送一封电子邮件:

<?
header('Content-Type: application/json; charset=utf-8');
$headers  = "From: Source\r\n";
    $headers .= "Content-type: text/html;charset=utf-8\r\n";
    $to = $data["t_email"];
    $subject = "Hello";
    $message = (gather_post("locale") == "fr_CA")?"message français ééààèè": "english message";
    mail($to, $subject, $message, $headers);
?>

我已经取出了不相关的部分。消息将正常发送,但重音符号将无法正确显示。一切都已设置为 utf-8 字符集,我不明白为什么这不起作用。

I have the following php script sends an email based on parameters returned:

<?
header('Content-Type: application/json; charset=utf-8');
$headers  = "From: Source\r\n";
    $headers .= "Content-type: text/html;charset=utf-8\r\n";
    $to = $data["t_email"];
    $subject = "Hello";
    $message = (gather_post("locale") == "fr_CA")?"message français ééààèè": "english message";
    mail($to, $subject, $message, $headers);
?>

I've taken parts out that are not relevent. The message will be sent out fine, but the accents will not appear correctly. Everything has been set as utf-8 charset, i don't understand why this isn't working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

佞臣 2024-12-20 11:01:40

您可能需要使用 utf8_encode() 对 html 进行编码。例如:

$message = utf8_encode("message français ééààèè");

我必须这样做才能动态导入法语 Word 文档,而且效果很好。如果这可以解决您的问题,请告诉我。

更新(示例工作代码)

<?php
$to      = '[email protected]';
$subject = 'subject';
$message = utf8_encode('message français ééààèè');
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

if(mail($to, $subject, $message, $headers)){
echo 'success!';
}
?>

You may have to encode the html with utf8_encode(). For example:

$message = utf8_encode("message français ééààèè");

I have had to do this to dynamically import French Word docs, and it works great. Let me know if this solves your problem.

UPDATE (example working code)

<?php
$to      = '[email protected]';
$subject = 'subject';
$message = utf8_encode('message français ééààèè');
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

if(mail($to, $subject, $message, $headers)){
echo 'success!';
}
?>
帅哥哥的热头脑 2024-12-20 11:01:40

要解决您的问题,您需要将以下行添加到发送电子邮件功能:

$headers .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";

以下是此行与电子邮件功能的集成:

function send_email($to,$subject,$message,$fromemail) {

    $headers = "From: $fromemail" . "\r\n";
    $headers .= "Return-Path: $fromemail" . "\r\n";
    $headers .= "Errors-To: $fromemail" . "\r\n";
    $headers .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
    @mail($to,$subject,$message,$fromemail);

}

To resolve your issue you need to add the following line to your send email function:

$headers .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";

Here is the integration of this line with an emailing function:

function send_email($to,$subject,$message,$fromemail) {

    $headers = "From: $fromemail" . "\r\n";
    $headers .= "Return-Path: $fromemail" . "\r\n";
    $headers .= "Errors-To: $fromemail" . "\r\n";
    $headers .= 'Content-type: text/plain; charset=UTF-8' . "\r\n";
    @mail($to,$subject,$message,$fromemail);

}
〆凄凉。 2024-12-20 11:01:40

请参阅这里我发现的好评论。只有这个对我有用。
https://ncona.com /2011/06/using-utf-8-characters-on-an-e-mail-subject/

详细信息:

to = '[email protected]';
$subject = 'Subject with non ASCII ó¿¡á';
$message = 'Message with non ASCII ó¿¡á';
$headers = 'From: [email protected]'."\r\n"
.'Content-Type: text/plain; charset=utf-8'."\r\n";
mail($to, '=?utf-8?B?'.base64_encode($subject).'?=', $message, $headers);

See here good comments I found. Only this works for me.
https://ncona.com/2011/06/using-utf-8-characters-on-an-e-mail-subject/

Details:

to = '[email protected]';
$subject = 'Subject with non ASCII ó¿¡á';
$message = 'Message with non ASCII ó¿¡á';
$headers = 'From: [email protected]'."\r\n"
.'Content-Type: text/plain; charset=utf-8'."\r\n";
mail($to, '=?utf-8?B?'.base64_encode($subject).'?=', $message, $headers);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文