贝宝:IPN 脚本不发送邮件
Paypal : IPN script doesn't send mail
此脚本无效:
IPN 脚本,不工作,我不知道为什么...
- 通知已开启(工作正常)。
- 我可以发邮件,没问题。
- 我认为是验证部分的问题...
- 我发了$req值到我的邮箱,里面都有数据。
IPN 脚本:
<?php
header('HTTP/1.1 200 OK');
// POST
$payer_email = $_POST['payer_email'];
$userID = $_POST['custom'];
$txn_id = $_POST['txn_id'];
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value"; }
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen('tls://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
fputs($fp, $header . $req);
while (!feof($fp)) { // While not EOF
$res = fgets($fp, 1024); // Get the acknowledgement response
if (strcmp ($res, "VERIFIED") == 0) { // Response contains VERIFIED - process notification
// Send an email announcing the IPN message is VERIFIED
$mail_From = "root@*******.fr";
$mail_To = "******@gmail.com";
$mail_Subject = "VERIFIED IPN";
$mail_Body = "good";
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
}
else if (strcmp ($res, "INVALID") == 0) { //Response contains INVALID - reject notification
// Authentication protocol is complete - begin error handling
// Send an email announcing the IPN message is INVALID
$mail_From = "root@*******.fr";
$mail_To = "******@gmail.com";
$mail_Subject = "INVALID IPN";
$mail_Body = "bad";
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
} }
fclose($fp); // Close the file
?>
我的问题已解决,问题是由 header 引起的:
PayPal IPN Bad Request 400 Error
此脚本无效:
IPN 脚本,不工作,我不知道为什么...
- 通知已开启(工作正常)。
- 我可以发邮件,没问题。
- 我认为是验证部分的问题...
- 我发了$req值到我的邮箱,里面都有数据。
IPN 脚本:
<?php
header('HTTP/1.1 200 OK');
// POST
$payer_email = $_POST['payer_email'];
$userID = $_POST['custom'];
$txn_id = $_POST['txn_id'];
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value"; }
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen('tls://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
fputs($fp, $header . $req);
while (!feof($fp)) { // While not EOF
$res = fgets($fp, 1024); // Get the acknowledgement response
if (strcmp ($res, "VERIFIED") == 0) { // Response contains VERIFIED - process notification
// Send an email announcing the IPN message is VERIFIED
$mail_From = "root@*******.fr";
$mail_To = "******@gmail.com";
$mail_Subject = "VERIFIED IPN";
$mail_Body = "good";
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
}
else if (strcmp ($res, "INVALID") == 0) { //Response contains INVALID - reject notification
// Authentication protocol is complete - begin error handling
// Send an email announcing the IPN message is INVALID
$mail_From = "root@*******.fr";
$mail_To = "******@gmail.com";
$mail_Subject = "INVALID IPN";
$mail_Body = "bad";
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
} }
fclose($fp); // Close the file
?>
我的问题已解决,问题是由 header 引起的:
PayPal IPN Bad Request 400 Error