php - PayPal IPN doesn't post to server

I have tried so many solutions to this problem, and seriously CANNOT find one. I have copied so many examples, and none work. This here, I know works, as my friend uses it on his website without error.

The IPN I have here I know works, as a friend gave it to me, and has received his IPN messages.

I checked my HTTP access logs, and PayPal never touches my server to post the data. On the PayPal IPN history page, it says "Retrying" for the payment.

My IPN and button code is below.


$req = 'cmd=_notify-validate';

// post back to PayPal system to validate //
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://', 443, $errno, $errstr, 30);

if (!$fp) {

    $mail_From = "From:";
    $mail_To = $email;
    $mail_Subject = "HTTP ERROR";
    $mail_Body = $errstr;

    mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
    $ids = explode("|", $_POST['custom']);
    $item_username = $ids[0];
    $item_userid = $ids[1];
    $item_email = $ids[2];
    $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'];
    $txnId = $_POST['txn_id'];
    $receiverEmail = $_POST['receiver_email'];
    $payerEmail = $_POST['payer_email'];
    $price = 4;
    $payment_amount = str_replace('.00', '', $payment_amount);

    fputs ($fp, $header . $req);
    while (!feof($fp)) {
        $res = fgets ($fp, 1024);
        $res = trim($res);
        if (strcmp($res, "VERIFIED")==0) {
            addPaypalPayment($item_name, $item_number, $item_username, $item_userid, $item_email, $payment_status, $payment_amount, $payment_currency, $txnId, $receiver_email, $payer_email, '1');
            serviceAdd($item_userid, $item_number, getNumServices($item_userid));
            setServiceActive($item_userid, $item_packageid);
            sendEmailWithUsername("Carwash", "PayPal IPN", "Success!");

            sendEmailWithUsername($_SESSION["username"], "Your new VPN purchase", "You can gain access to your new VPN account by visiting <a href=''>this</a> link.");
        else if (strcmp($res, "INVALID")==0) {
            $mail_To = $email;
            $mail_Subject = "PayPal - Invalid IPN ";
            $mail_Body = "We have had an INVALID response. \n\nThe transaction ID number is: $txn_id \n\n username = $username";
            mail($mail_To, $mail_Subject, $mail_Body);
    } //end of while
    fclose ($fp);


<form action="https://<?php echo $url; ?>/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick"/>
    <input type="hidden" name="business" value="<?php echo $email; ?>"/>
    <input type="hidden" name="item_name" value="<?php echo $pname; ?>"/>
    <input type="hidden" name="item_number" value="<?php echo $id; ?>"/>
    <input type="hidden" name="amount" value="<?php echo $prices[$id - 1] . ".00"; ?>"/>
    <input type="hidden" name="quantity" value="1"/>
    <input type="hidden" name="no_note" value="1"/>
    <input type="hidden" name="currency_code" value="USD"/>
    <input type="hidden" name="lc" value="US"/>
    <input type="hidden" name="bn" value="PP-BuyNowBF"/>
    <input type="hidden" name="return"
           value="<?php echo $id; ?>&met=<?php echo $met; ?>"/>
    <input type="hidden" name="cancel_return"
           value="<?php echo $id; ?>&met=<?php echo $met; ?>&do=2"/>
    <input type="hidden" name="notify_url" value=""/>
    <input type="hidden" name="custom" value="<?php echo $_SESSION['username'].'|'.getUserId($_SESSION["username"]).'|'.getUserEmail($_SESSION["username"]); ?>"/>
    <div style="padding-top:100px; padding-right: 40%; padding-left: 40%;">
        <center><input type="submit" name="submit" class="btn" value="Checkout with PayPal"></center>

1 Answer

  1. Oscar- Reply


    One possible reason is that your post back header is out of date.

    $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

    Should now read:

    $header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "\r\n";
    $header .= "Connection:close\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

    Paypal have stopped supporting HTTP1.0

    Hope this helps

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>