gpt4 book ai didi

php - PayPal IPN - 无法接收电子邮件通知

转载 作者:太空宇宙 更新时间:2023-11-03 15:59:25 25 4
gpt4 key购买 nike

我正在尝试在我的项目中实现 PayPal 并设置 IPN(通过 PayPal 沙箱)以接收付款通知。我创建了一个 dev 帐户并有两个 email 地址。一份给卖家 (seller-facilitator@someDomain.com),一份给买家。我将 php 文件在线存储在我的站点中,并在卖家帐户上配置 ipn url,如下所示:

http://example.org/someFolder/ipnsample.php

当我尝试模拟 IPN 时,我收到一条消息 IPN was sent and the handshake was verified. 所以配置似乎没问题,但我无法接收任何通知到我的邮件。

PHP:

   // Send an empty HTTP 200 OK response to acknowledge receipt of the notification 
header('HTTP/1.1 200 OK');

// Assign payment notification values to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];

// Build the required acknowledgement message out of the notification just received
$req = 'cmd=_notify-validate'; // Add 'cmd=_notify-validate' to beginning of the acknowledgement

foreach ($_POST as $key => $value) { // Loop through the notification NV pairs
$value = urlencode(stripslashes($value)); // Encode these values
$req .= "&$key=$value"; // Add the NV pairs to the acknowledgement
}

// Set up the acknowledgement request headers
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Host: www.sandbox.paypal.com\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);

// Open a socket for the acknowledgement request


// Send the HTTP POST request back to PayPal for validation
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 = "IPN@example.com";
$mail_To = "My@Mail.com";
$mail_Subject = "VERIFIED IPN";
$mail_Body = $req;
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
}
else if (strcmp ($res, "INVALID") == 0) {
// Authentication protocol is complete - begin error handling

// Send an email announcing the IPN message is INVALID
$mail_From = "IPN@example.com";
$mail_To = "My@Mail.com";
$mail_Subject = "INVALID IPN";
$mail_Body = $req;

mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
}
}

fclose($fp); // Close the file

HTML(购买表格):

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="seller-facilitator@someDomain.com">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="item_name" value="Trex hide">
<input id="PayPalPrice1" type="hidden" name="amount" value="">
<button name="submit" class="btn btn-lg btn-success "> Checkout With <b> PayPal </b> </button>
</form>

最佳答案

首先检查邮件方法是否正常工作:

  $mail_From    = "IPN@example.com";
$mail_To = "My@Mail.com";
$mail_Subject = "VERIFIED IPN";
$mail_Body = $req;
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);

只需将代码放在监听器 php 文件的顶部并刷新页面即可。如果邮件方法工作正常,只需在 while() 之前使用 serialize($fp) 方法调试变量 $fp

  $mail_From    = "IPN@example.com";
$mail_To = "My@Mail.com";
$mail_Subject = "VERIFIED IPN";
$mail_Body = serialize($fp);
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);

关于php - PayPal IPN - 无法接收电子邮件通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33993906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com