无法处理通过我的电子邮件表单发送的消息。任何人都可以帮助我吗?这是我的代码:

Can´t get accentuation to work on messages sent with my email form. Anyone can give me a hand? Here is my code:

消息显示如下: 狗醒水椰测试加重

这就是我想要显示的内容: 狗叫醒椰子水压力测试

有人可以帮帮我吗?我将不胜感激。

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if(!empty($_POST['contactname']) && !empty($_POST['contactemail']) && !empty($_POST['contactmessage'])) {
        $to = 'email@gmail.com'; // Your e-mail address here.
        $body = "\nNCliente: {$_POST['contactname']}\nEmail: {$_POST['contactemail']}\n\n\n{$_POST['contactmessage']}\n\n";
        mail($to, "Mensagem de ", $body, "From: {$_POST['contactemail']}"); // E-Mail subject here.
    }
}
?>

这看起来像是编码问题。如果您想显示像“ç”这样的典型葡萄牙语字符,您需要将文本参数解码为 UTF-8 模式。这样,它们就会正确显示。

为此,您可以尝试使用 PHP 中的 utf8_decode(string) 函数。像这样:

$contactname = utf8_decode($_POST['contactname']);

编辑: 您的代码如下所示:

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if(!empty($_POST['contactname']) && !empty($_POST['contactemail']) && !empty($_POST['contactmessage'])) {

    //this is the part where you convert to utf8 pattern
    $namecontact = utf8_decode($_POST['contactname']);
    $messagecontact = utf8_decode($_POST['contactmessage']);

    $to = 'email@gmail.com'; // Your e-mail address here.

    $body = "\nNCliente: " .$namecontact. "\nEmail: {$_POST['contactemail']}\n\n\n". $messagecontact ."\n\n";
    mail($to, "Mensagem de ", $body, "From:" . $namecontact); // E-Mail subject here.
}
}
?>