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有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口