Paypal:IPN脚本不发送邮件

时间:2016-01-19 10:56:53

标签: php paypal paypal-ipn

此脚本无效:

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

?>

1 个答案:

答案 0 :(得分:0)

我的问题解决了,问题是由标题引起的:
PayPal IPN Bad Request 400 Error

相关问题