douyin2883 2013-04-27 17:01 采纳率: 0%
浏览 86
已采纳

PHP PayPal IPN和UTF-8

I have tried to read up on this issue and checked examples but havent found a way to figure this out. When my confirmation letter is sent to buyer/seller the ÅÄÖ or other special characters will be corrupt and how do I change this? Heres a screenshot: http://snag.gy/7IFDQ.jpg

As you can see both the text and the subject is corrupt.

I have of course changed to utf-8 in the PayPal profile. This is something else. I found a way after a long long time to fix it for the PDT but now the "same" issue is bugging me on the IPN side.

Anyone that knows how to exactly fix this? I can paste IPN.php and Ipnhandler if you want me to.

  • 写回答

1条回答 默认 最新

  • dongyuli4538 2013-04-30 16:18
    关注

    I found out how you do this, you will need to set UTF-8 in the mail itself and in extension both in the header of the mail (Subject and so on) and the message in the mail as well.

    Heres a code sample that sends a mail to the customr and a copy to the seller:

    // send user an email with a confirmation
        $firstname = $_POST['first_name'];
        $lastname = $_POST['last_name'];
        $to = filter_var($_POST['payer_email'], FILTER_SANITIZE_EMAIL);
        $to2 = filter_var($_POST['your@email.com'], FILTER_SANITIZE_EMAIL);
        $subject = "Tack för Ert köp! / Thank you for your order!";
        $subject2 = "(COPY) Tack för Ert köp! / Thank you for your order!";
        $headerFields = array(
        'Date: ' . date('r', $_SERVER['REQUEST_TIME']),
        "Subject: =?UTF-8?Q?".imap_8bit($subject)."?=",
        "From: {$to}",
        "MIME-Version: 1.0",
        "Content-Type: text/html;charset=utf-8"
        );
        $headerFields2 = array(
        'Date: ' . date('r', $_SERVER['REQUEST_TIME']),
        "Subject: =?UTF-8?Q?".imap_8bit($subject2)."?=",
        "From: {$to}",
        "MIME-Version: 1.0",
        "Content-Type: text/html;charset=utf-8"
        );
        $message = "$firstname $lastname, $payer_email <br />
    MESSAGE TO CUSTOMER;
        $message2 = "$firstname $lastname, $payer_email <br />
    MESSAGE TO CUSTOMER
    (NOTE: THIS IS A COPY)";
        mail($to, $subject, $message,  implode("
    ", $headerFields));
        mail($to2, $subject2, $message2,  implode("
    ", $headerFields2));   
        }
    

    What is happening is that the $headerFields "MIME-Version: 1.0", "Content-Type: text/html;charset=utf-8" sets UTF-8 for the message of the mail. It even applies to the header except for the Subject that needs to be alone set to: "Subject: =?UTF-8?Q?".imap_8bit($subject)."?=",

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

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。