Take the 2-minute tour ×

There is paypal button on page. There are 2 custom fields with paypal button. I am getting IPN response on ipn.php page. I have got this code from paypal site.

When I am testing using SandBox, Payment is deduced from buyer account and deposited into merchant account. But data are not inserted into database table that I mentioned at last of below code. I have also tried to send both variable values in single variable named "custom" but still no luck. Please review my code and let me know what wrong I am doing. Please help me as I am struggling for last 2 days.

$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
  $keyval = explode ('=', $keyval);
  if (count($keyval) == 2)
      $myPost[$keyval[0]] = urldecode($keyval[1]);

$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
$get_magic_quotes_exists = true;
foreach ($myPost as $key => $value) {        
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { 
    $value = urlencode(stripslashes($value)); 
} else {
    $value = urlencode($value);

$ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

if( !($res = curl_exec($ch)) ) {
// error_log("Got " . curl_error($ch) . " when processing IPN data");

$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'];
$custom_memname = $_POST['custom_memname']; // This is 1st custom variable
$custom_mempass = $_POST['custom_mempass']; // This is 2nd custom variable

$str_query_insert="insert into t_fmember(memberid,password) values('" .$custom_memname."','".$custom_mempass."')";  

I added this code on my ipn.php page and used IPN Simulator but didn't get any response yet.

$post_data_string = serialize($_POST);
mail('mymail@yahoo.com', 'PayPal IPN', $post_data_string);

Please help further if possible. Thank you

share|improve this question
Silly question but you know that in sandbox mode PayPal does not send IPN responses to your server don't you? You need to use the IPN Simulator in the developer tools. –  toomanyredirects Feb 21 '13 at 10:39
I accept silliness for question but I had no clue so I will do what you suggested. Thank you very much. –  KRA Feb 21 '13 at 10:45
No problem. I've re-posted as an answer, if this solves your problem please accept. –  toomanyredirects Feb 21 '13 at 10:47
@toomanyredirects is that true ? –  Abhishek K Apr 15 at 12:05

1 Answer 1

You need to use the PayPal Sandbox IPN Simulator at http://developer.paypal.com in order to test IPN notifications in sandbox mode.

share|improve this answer

Your Answer


