简体   繁体   中英

Paypal : IPN script doesn't send mail

This script is not working :

The IPN script, Is not working, I don't know why ...

  • Notification is ON (It's working fine).
  • I can send mail, no problem.
  • I think that the verification part is the problem ...
  • I send $req value to my mail, and there are all datas.


IPN Script :

<?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

?>

My problem is resolved, the problem was caused by the header :
PayPal IPN Bad Request 400 Error

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM