我已设法设置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更改),但仍然只有卖家收到邮件。这是为什么?
答案 0 :(得分:0)
发现我的webhost在其域外的限制为25mail /天,然后它不再工作了,还必须定义receiver_email以使其“在域内”。这适用于one.com作为webhost。
使用完全正常的脚本更新了脚本,并在标题和消息中添加了Date,From,UTF-8,并在消息中添加了格式良好的文本。