doubei2231 2016-12-21 04:20
浏览 52
已采纳

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

I am using php mailer at my website contact form. When i receive a message in greek language, i don't receive the text as typed in the contact form. In class.phpmailer.php file line 59 the encoding is public $CharSet = 'iso-8859-1'; Is there a way to make my text appear correctly as typed in the contact form?

Languages comonly supported by ISO/IEC 8859-1 can be found here

I have also tried german and albanian languages but i also have the same problem. I can only receive english, if the user types another language on some words i receive "chinese".

enter image description here

I get this message: enter image description here

The code:

     <?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:

_____
          ___________________
" . "
Dear $from_name,

      Your enquiry had been received on " . date("D j F ") . "
       
INFORMATION SUBMITTED: " . "

Name: $from_name

Email: $from
        
Subject: $subject

Message: $body 

To:
         $to
Date: " . date("d/m/y") . "
Website: " . "
____________
        __________________"; //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!

    We will reply to the following email: $from" . "
Your Message: $body";
            }




        } //end function smtpmailer
        //}


        ?>

展开全部

  • 写回答

1条回答 默认 最新

  • doufen2769 2016-12-21 04:46
    关注

    In your example output, the char count amplification suggests that you're receiving data from your form in UTF-8, but are then telling PHPMailer (by default) that it's ISO-8859-1, which results in the kind of corruption you're seeing.

    You should be using UTF-8 everywhere. In PHPMailer you do it like this:

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

    Then you need to be sure that every step of your processing supports UTF-8 as well.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部