title: paypal sandbox responds bad request
body: <p>I have following HTML form</p>
  
  <pre><code>&lt;form action="https://sandbox.paypal.com/cgi-bin/webscr" method="post" id="paypalpost" name="paypalpost"&gt;
                  &lt;input type="hidden" name="rm" value="2"/&gt;
                  &lt;input type="hidden" name="cmd" value="_xclick"&gt;
                  &lt;input type="hidden" name="business" value="vbnetdiscuss@yahoo.com"&gt;
                  &lt;input type="hidden" name="item_name" value="Wedding Gift"&gt;
                  &lt;input type="hidden" name="currency_code" value="EUR"&gt;
                  &lt;input type="hidden" name="amount" value="&lt;?php echo $value['total'];?&gt;"&gt;
                  &lt;input type="hidden" name="return" value="http://developwithus.com/wedding/return.php"&gt;
                  &lt;input type="hidden" name="cancel_return" value="http://developwithus.com/wedding/return.php?status=0"&gt;
  
  
              &lt;input onclick="return submitatoc();" disabled type="submit" name="submit" id="pay" class="buttonBlueBg" value="Checkout" style="cursor:pointer;"&gt;
  
              &lt;/form&gt;
  </code></pre>
  
  <hr>
  
  <p>I had mentioned return URL as <a href="http://developwithus.com/wedding/return.php" rel="noreferrer">http://developwithus.com/wedding/return.php</a>
  on which, (I had download this from : <a href="https://cms.paypal.com/cms_content/US/en_US/files/developer/IPN_PHP_41.txt" rel="noreferrer">https://cms.paypal.com/cms_content/US/en_US/files/developer/IPN_PHP_41.txt</a> and add 
  
  <pre><code>&lt;?php 
  print_r('&lt;pre&gt;');
  print_r($_POST);
  // read the post from PayPal system and add 'cmd'
  $req = 'cmd=_notify-validate';
  
  foreach ($_POST as $key =&gt; $value) {
      $value = urlencode(stripslashes($value));
      $req .= "&amp;$key=$value";
  }
  
  // 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://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
  
  // 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'];
  
  if (!$fp) {
  // HTTP ERROR
      echo "HTTP Error";
  } else {
      fputs ($fp, $header . $req);
      while (!feof($fp)) {
          $res = fgets ($fp, 1024);
          echo $res;
          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
              echo("verified");
          }
          else if (strcmp ($res, "INVALID") == 0) {
              // log for manual investigation
              echo ("invalid");
          }
      }
      fclose ($fp);
  }
  echo "end";
  ?&gt;
  </code></pre>
  
  <p>but I got Bad Request as response, If I go to paypal sand box account and made payment and return back.</p>
  
  <pre><code>Array
  (
     [CONTEXT] =&gt; wtgSziM4C5x0SI-9CmKcv2vkSeTLK5P_g6HqzC__YTYkcqziFNcB84p79Ja
     [myAllTextSubmitID] =&gt; 
     [cmd] =&gt; _flow
     [mc_gross] =&gt; 100.00
     [protection_eligibility] =&gt; Ineligible
     [address_status] =&gt; confirmed
     [payer_id] =&gt; Z5NWSYYVZW268
     [tax] =&gt; 0.00
     [address_street] =&gt; 1 Main St
     [payment_date] =&gt; 09:04:08 May 14, 2011 PDT
     [payment_status] =&gt; Pending
     [charset] =&gt; windows-1252
     [address_zip] =&gt; 95131
     [first_name] =&gt; Test
     [address_country_code] =&gt; US
     [address_name] =&gt; Test User
     [notify_version] =&gt; 3.1
     [custom] =&gt; 
     [payer_status] =&gt; verified
     [address_country] =&gt; United States
     [address_city] =&gt; San Jose
     [quantity] =&gt; 1
     [payer_email] =&gt; sujeet_1302606445_per@gmail.com
     [verify_sign] =&gt; AozIjtjfCe0jUnbJpR4qPrW54olKAq.SrnEktGSocrk8yYv4bpR4lJX7
     [txn_id] =&gt; 3HG58230W32603443
     [payment_type] =&gt; instant
     [last_name] =&gt; User
     [address_state] =&gt; CA
     [receiver_email] =&gt; vbnetdiscuss@yahoo.com
     [pending_reason] =&gt; unilateral
     [txn_type] =&gt; web_accept
     [item_name] =&gt; Wedding Gift
     [mc_currency] =&gt; EUR
     [item_number] =&gt; 
     [residence_country] =&gt; US
     [test_ipn] =&gt; 1
     [transaction_subject] =&gt; Wedding Gift
     [handling_amount] =&gt; 0.00
     [payment_gross] =&gt; 
     [shipping] =&gt; 0.00
     [merchant_return_link] =&gt; click here
     [form_charset] =&gt; UTF-8
  )
  HTTP/1.1 400 Bad Request
  Date: Sat, 14 May 2011 16:05:20 GMT
  Server: Apache
  Set-Cookie: c9MWDuvPtT9GIMyPc3jwol1VSlO=%7cgA9mW0Yh7-iBp435VBDwyCqtOtnlE8KAk8fT_sjGXHGx2mDzXgFit5ZdHd3BOOEUt_UDRW%7cRD1g8aAyLevIAP-u4WfCokEQkimrkpQk6v6rLZ_xD-pT1ATWuv5RtcK3NIbPPwfF1cXq3G%7c; domain=.paypal.com; path=/; Secure; HttpOnly
  Set-Cookie: cookie_check=yes; expires=Tue, 11-May-2021 16:05:20 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
  Set-Cookie: Apache=10.191.196.11.9095130538912094; path=/; expires=Fri, 31-Mar-05 09:37:04 GMT
  Connection: close
  Content-Type: text/plain; charset=ISO-8859-1
  </code></pre>
  
  <p>can you guys tell me what I'm doing wrong? 
  INVALID response is working </p>