douchen7324 2013-04-27 17:27
浏览 53
已采纳

PHP PayPal IPN确认邮件问题

I have managed to setup PDT and now to IPN. The problem is that the seller account do get a confirmation mail but not the buyer even though I use the same code, it doesnt make sense.

Heres my IPN.php:

        <?php
header('Content-type: text/html; charset=utf-8');
?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<?php
// tell PHP to log errors to ipn_errors.log in this directory
ini_set('log_errors', true);
ini_set('error_log', dirname(__FILE__).'/ipn_errors.log');

// intantiate the IPN listener
include('ipnlistener.php');
$listener = new IpnListener();

// tell the IPN listener to use the PayPal test sandbox
$listener->use_sandbox = true;

// try to process the IPN POST
try {
    $listener->requirePostMethod();
    $verified = $listener->processIpn();
} catch (Exception $e) {
    error_log($e->getMessage());
    exit(0);
}

if ($verified) {
    $errmsg = '';   // stores errors from fraud checks

    // 1. Make sure the payment status is "Completed" 
    if ($_POST['payment_status'] != 'Completed') { 
        // simply ignore any IPN that is not completed
        exit(0); 
    }

    // 2. Make sure seller email matches your primary account email.
    if ($_POST['receiver_email'] != '*****') {
        $errmsg .= "'receiver_email' does not match: ";
        $errmsg .= $_POST['receiver_email']."
";
    }

    // 3. Make sure the amount(s) paid match
    /*if ($_POST['mc_gross'] != '9.99') {
        $errmsg .= "'mc_gross' does not match: ";
        $errmsg .= $_POST['mc_gross']."
";
    }*/

    // 4. Make sure the currency code matches
    if ($_POST['mc_currency'] != 'USD') {
        $errmsg .= "'mc_currency' does not match: ";
        $errmsg .= $_POST['mc_currency']."
";
    }

    // 5. Ensure the transaction is not a duplicate.
    mysql_connect('*****', '*****', '*****') or exit(0);
    mysql_select_db('*****') or exit(0);

    $txn_id = mysql_real_escape_string($_POST['txn_id']);
    $sql = "SELECT COUNT(*) FROM orders WHERE txn_id = '$txn_id'";
    $r = mysql_query($sql);

    if (!$r) {
        error_log(mysql_error());
        exit(0);
    }

    $exists = mysql_result($r, 0);
    mysql_free_result($r);

    if ($exists) {
        $errmsg .= "'txn_id' has already been processed: ".$_POST['txn_id']."
";
    }

    if (!empty($errmsg)) {

        // manually investigate errors from the fraud checking
        $body = "IPN failed fraud checks: 
$errmsg

";
        $body .= $listener->getTextReport();
        mail('*****', 'IPN Fraud Warning', $body);

    } else {

    // add this order to a table of completed orders
    $payer_email = mysql_real_escape_string($_POST['payer_email']);
    $mc_gross = mysql_real_escape_string($_POST['mc_gross']);
    $sql = "INSERT INTO orders VALUES 
            (NULL, '$txn_id', '$payer_email', $mc_gross)";

    if (!mysql_query($sql)) {
        error_log(mysql_error());
        exit(0);
    }

    // send user an email with a link to their digital download
    $num = $_POST['num_cart_items'];
    $amount = $_POST['mc_gross'];
    $firstname = $_POST['first_name'];
    $lastname = $_POST['last_name'];
    $to = filter_var($_POST['payer_email'], FILTER_SANITIZE_EMAIL);
    $to2 = filter_var($_POST['*****'], 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 />
Du köpte $num produkter för totalt $amount kronor. Alla priser är i svenska kronor inklusive moms, 12% respektive 25% (12% moms på EnergyUnion, 25% moms på resten av sortimentet) <br />
You bought $num products for a total of $amount Swedish kronor. All prices are in Swedish kronor, including VAT, 12% and 25% respectively (12% Tax on Energy Union, 25% VAT on the rest of the product range) <br />
Välkommen åter! <br>
Hälsningar, <br>
*****";
    $message2 = "$firstname $lastname, $payer_email <br />
Du köpte $num produkter för totalt $amount kronor. Alla priser är i svenska kronor inklusive moms, 12% respektive 25% (12% moms på EnergyUnion, 25% moms på resten av sortimentet) <br />
You bought $num products for a total of $amount Swedish kronor. All prices are in Swedish kronor, including VAT, 12% and 25% respectively (12% Tax on Energy Union, 25% VAT on the rest of the product range) <br />
Välkommen åter! <br>
Hälsningar, <br>
***** <br />
(NOTE: THIS IS A COPY)";
    mail($to, $subject, $message,  implode("
", $headerFields));
    mail($to2, $subject2, $message2,  implode("
", $headerFields2));   
    }

} else {
    // manually investigate the invalid IPN
    mail('*****', 'Invalid IPN', $listener->getTextReport());
}


?>

And if you look at the bottom of it you can see that I try to send 2 mails, one to the buyer and one to the seller with practically identical code (only mailadress changes), but still only seller gets the mail. Why is this?

  • 写回答

1条回答 默认 最新

  • doutao6380 2013-04-30 16:07
    关注

    Found out that my webhost has a limit of 25mail/day OUTSIDE their domain and then it wont work anymore, also that receiver_email has to be defined so its "within" the domain. This applied to one.com as webhost.

    Updated the script with fully working one and added Date, From, UTF-8 in both header and message and nicely formatted text in the message.

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

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改