PHP Mailer语言编码问题:它只接受英语

时间:2016-12-21 12:20:19

标签: php phpmailer

我在我的网站联系表格中使用php邮件程序。当我收到希腊语的消息时,我没有收到联系表格中输入的文字。在class.phpmailer.php文件第59行中,编码是public $CharSet = 'iso-8859-1';有没有办法让我的文本在联系表单中输入正确?

  

ISO / IEC 8859-1共同支持的语言可以找到here

我也尝试过德语和阿尔巴尼亚语,但我也有同样的问题。我只能接收英语,如果用户在某些单词上键入另一种语言,我会收到“中文”。

enter image description here

  

我收到此消息:   enter image description here

代码:

     <?php
        require_once('phpmailer/class.phpmailer.php');

        // if(isset($_POST['g-recaptcha-response'])){
        if (empty($_POST['Email'])) {
            $_POST['Email'] = "-";
        }
        if (empty($_POST['Name'])) {
            $_POST['Name'] = "-";
        }
        if (empty($_POST['Subject'])) {
            $_POST['Subject'] = " ";
        }
        if (empty($_POST['message'])) {
            $_POST['message'] = "-";
        }




        $mymail = smtpmailer("example@gmail.com", $_POST['Email'], $_POST['Name'],
 $_POST['Subject'], $_POST['message']);
        function smtpmailer($to, $from, $from_name, $subject, $body)
        {
            $mail = new PHPMailer;
            $mail->isSMTP();
            $mail->Debugoutput = 'html';
            $mail->Host        = 'smtp.gmail.com';
            $mail->Port        = 587;
            $mail->SMTPSecure  = 'tls';
            $mail->SMTPAuth    = true;
            $mail->Username    = 'example@gmail.com';
            $mail->Password    = 'pass';
            $mail->SetFrom($from, $from_name);
            $mail->Subject  = " Contact form ~Name: $from_name ~ subject: $subject  ";
         $mail->Body = " You have received a new message 
          from $from_name, here are the details:\n\n_____
          ___________________\n" . "\nDear $from_name,\n
      Your enquiry had been received on " . date("D j F ") . "
       \nINFORMATION SUBMITTED: " . "\n\nName: $from_name\n\nEmail: $from
        \nSubject: $subject\n\nMessage: $body \n\nTo:
         $to\nDate: " . date("d/m/y") . "\nWebsite: " . "\n____________
        __________________"; //end body


        $mail->AddAddress($to);
        //send the message, check for errors
        if (!$mail->send()) {
          echo "Mailer Error: " . $mail->ErrorInfo;

         } else {
       echo "Well done $from_name, your message has been sent!\n
    We will reply to the following email: $from" . "\nYour Message: $body";
            }




        } //end function smtpmailer
        //}


        ?>

1 个答案:

答案 0 :(得分:3)

在你的示例输出中,char计数放大表明你正在以UTF-8从表单接收数据,但是然后告诉PHPMailer(默认情况下)它是ISO-8859-1,这导致了你看到的腐败。

你到处都应该使用UTF-8。在PHPMailer中你可以这样做:

$mail->CharSet  = 'UTF-8';

然后你需要确保你的处理的每一步都支持UTF-8。