尽管使用utf-8,PHP仍会发送带问号的邮件

时间:2015-11-11 19:01:50

标签: php email utf-8

使用以下php文件发送邮件。 但是邮件正文里面不是英文的文字却是????邮件的$主题为“,Ã,ºÃƒÃ,ƒÃÂ,Ã,«Ô

我需要检查/添加/更改以修复它?

<?php include('config.php');
header('Content-Type: text/html; charset=utf-8');

class messenger
{

    public $name;
    public $number;
    public $email;
    public $address;
    public $category;
    public $tool;

    /*----------user registration start--------------*/
    function signup()
    {

        $name = $_REQUEST['name'];
        $number = $_REQUEST['number'];
        $email = $_REQUEST['email'];
        $address = $_REQUEST['address'];
        $category = $_REQUEST['category'];
        $tool = $_REQUEST['tool'];
        $datetime = date("Y-m-d H:i:s");

        //Generate the email message:
        $to = 'someEmailAddress@gmail.com';
        $subject = "הזמנת חדשה";
        $msg = "In time: " . $datetime . "\n New Power Tool Rental: \n\n            Name: " . $name . "\r\n            Email: " . $email . "\n            Mobile Number: " . $number . "\n            Address: " . $address . "\n            Category: " . $category . "\n            Tool: " . $tool . "\n\n Regards\n " . $name . " \n " . $email;
        $headers = "From:  $email" . "\r\n";
        $headers .= "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type: text/plain; charset=UTF-8";
        $headers .= "X-Mailer: PHP/" . phpversion();

        //Send the email
        mail($to, $subject, $msg, $headers);

        //Enter data to the SQL table
        $sql = "INSERT INTO user (name, number, email, address, category, tool, dateTime)
                 VALUES ('$name', '$number', '$email', '$address', '$category', '$tool','$datetime')";

        //Check if entered to SQL and if Yes send back in json message
        $result = mysql_query($sql);
        if (!$result) {
            $message["result"] = "Problemmm";
        } else {
            $mysql_insert_id = mysql_insert_id();       //get the new ID number from sql table
            $message["id"] = $mysql_insert_id;          //add the new ID data to the response message
            $message["name"] = $_REQUEST['name'];
            $message["number"] = $_REQUEST['number'];
            $message["email"] = $_REQUEST['email'];
            $message["address"] = $_REQUEST['address'];
            $message["result"] = "successfully";
        }

        //Send back the json message
        echo json_encode($message);
        die;
    }
    /*----------user registration end--------------*/
}

?>

试图将主题更改为:

$subject = "הזמנת כלי להשכרה";
$encSubject = '=?UTF-8?B?'.base64_encode($subject).'?=';

现在我将邮件的主题视为: ú é

1 个答案:

答案 0 :(得分:1)

设置标题是不够的。

subject(必须为RFC 2047)和。{ message(在你的情况下必须是UTF-8)也有相应的正确编码,php :: mail doc + user-notes涵盖了你想念的大部分内容。