Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    177
    Thanks
    20
    Thanked 2 Times in 1 Post

    Paypal IPN help!!

    Hello all! I've had this paypal IPN for some time now and it works perfectly. So here's what happens:

    The user pressed "purchase now" on my site and they pay the selected amount, then this script is run somewhere down the line and the paypal users receives an email with the contents below. This works perfectly, but I would like one more thing to happen.

    I have an online mailing list that users can subscribe to by clicking a link on my home site. It stores the email address in a text file, which looks like this:


    Code:
    "email@mail.com","1266585584","2323123222" 
    "email2@mail.com","1266585584","2323123222" 
    "email3@mail.com","1266585584","2323123222"

    I don't know what it would be or where to put it, but it would somehow write the user's paypal email into that text file, so they are subscribed to the mailing list. Here's my IPN code:


    PHP Code:
    <?php
    // read the post from PayPal system and add 'cmd'
    $req 'cmd=_notify-validate';

    foreach (
    $_POST as $key => $value) {
    $value urlencode(stripslashes($value));
    $req .= "&$key=$value";
    }

    // post back to PayPal system to validate
    $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
    $header .= "Host: www.paypal.com:443\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " strlen($req) . "\r\n\r\n";

    $fp fsockopen ('ssl://www.paypal.com'443$errno$errstr30);

    // assign posted variables 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'];

    //set email variables
    $From_email "From: email@email.com";
    $Subject_line "Thing";
    $email_msg "Body Contents
    "
    ;

    if (!
    $fp) {
    // HTTP ERROR
    } else {
    fputs ($fp$header $req);
    while (!
    feof($fp)) {
    $res fgets ($fp1024);
    if (
    strcmp ($res"VERIFIED") == 0) {
    // check the payment_status is Completed
    // check that txn_id has not been previously processed
    // check that receiver_email is your Primary PayPal email
    // check that payment_amount/payment_currency are correct
    // process payment

    $mail_From $From_email;
    $mail_To $payer_email;
    $mail_Subject $Subject_line;
    $mail_Body $email_msg;

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


    }
    else if (
    strcmp ($res"INVALID") == 0) {
    // log for manual investigation

    $mail_From $From_email;
    $mail_To $receiver_email;
    $mail_Subject "Oops!";
    $mail_Text "Something went wrong.
    "
    ;

    mail($mail_To$mail_Subject$mail_Text$mail_From);

    }
    }
    fclose ($fp);
    }
    ?>
    Thank you in advance!

  • #2
    Regular Coder
    Join Date
    Oct 2009
    Posts
    177
    Thanks
    20
    Thanked 2 Times in 1 Post
    No one?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •