doubei2231 2016-12-21 12: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 12: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.

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

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探