PHP 表单 - 如何发送包含 UTF-8 字符的电子邮件


PHP form - How to sent email that contain UTF-8 character

我正在继续开发以前开发人员的网络,允许用户发送查询表单。一些用户是中国人,因此他们在填写表格时倾向于使用汉字。当他们发送表格时,我收到的电子邮件将显示此内容

å ‰éš†å ¡/雪兰莪州

有没有办法解决这个问题?这是代码

query_process.php:

<?php
session_start();
require_once "includes/phpmailer.php";

$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
$subject = mysql_real_escape_string($_POST['subject']);
$message = mysql_real_escape_string($_POST['message']);

$subject = "[Website] Contact Form";
$body = "<p>Name: $name</p>
         <p>Email: $email</p>
         <p>Subject: $subject</p>
         <p>Message : $message</p>
        ";
        //$cf_mail_replyto
if(sendPHPMail('___', '___', '___', $subject, $body))
    echo "success";
else
    echo "fail";
?>

query_from.php:

...
function submitForm()
{
    if($("#name").val() == "")
        alert("Sorry, please fill in your name.");
        else
            if($("#email").val() == "")
        alert("Sorry, please fill in your email.");
        else
            if($("#subject").val() == "")
        alert("Sorry, please fill in your subject.");
        else
            if($("#message").val() == "")
        alert("Sorry, please fill in your message.");
    else
    {
        $.ajax({
            type: "POST",
            url: "query_process.php",
            data: $("#enquiry").serialize(),
            success: function(data){
                if(data == "success"){
                    alert("Your enquiry has been sent successfully.");
                window.location.reload();
                }
                else{
                    //console.log(data);
                    //alert(data);
                alert("There's problem sending your enquiry. Please try again later.");
                }
            }
        });
    }
}
...
</script>
//my form
...
  1. 不要再使用 MySQL 扩展
  2. 您到底为什么要在电子邮件上下文中使用mysql_real_escape_string
  3. 您使用什么电子邮件查看器
  4. sendPHPMail函数中到底有什么?这是phpmailer类的包装器吗?检查 无法使用 PHPMailer 发送带有正确字符的电子邮件,了解如何使用 phpmailer 发送 UTF-8 邮件。
  5. 包含表单的 HTML 页面是否具有适当的 UTF-8 编码?