我已经设法设置 PDT,现在设置为 IPN。问题是即使我使用相同的代码,卖家账户确实会收到一封确认邮件,但买家却没有,这没有意义。
这是我的 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']."\n";
}
// 3. Make sure the amount(s) paid match
/*if ($_POST['mc_gross'] != '9.99') {
$errmsg .= "'mc_gross' does not match: ";
$errmsg .= $_POST['mc_gross']."\n";
}*/
// 4. Make sure the currency code matches
if ($_POST['mc_currency'] != 'USD') {
$errmsg .= "'mc_currency' does not match: ";
$errmsg .= $_POST['mc_currency']."\n";
}
// 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']."\n";
}
if (!empty($errmsg)) {
// manually investigate errors from the fraud checking
$body = "IPN failed fraud checks: \n$errmsg\n\n";
$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("\r\n", $headerFields));
mail($to2, $subject2, $message2, implode("\r\n", $headerFields2));
}
} else {
// manually investigate the invalid IPN
mail('*****', 'Invalid IPN', $listener->getTextReport());
}
?>
如果您查看它的底部,您会看到我尝试发送 2 封邮件,一封给买家,一封给卖家,其代码几乎相同(只有 mailadress 更改),但仍然只有卖家收到邮件。为什么是这样?