title: Paypal PDT error 4003
body: <p>After many hours of messing about and trying to set up what should be the relatively simple process of sending a payment to www.sandbox.paypal.com and being redirected back to a page on my site with a transaction id in the querystring, I have finally achieved it.</p>
  
  <p>I am now receiving an error message 'FAIL Error 4003'. </p>
  
  <p>Here is the code I am using. It is pretty much the same as the paypal example (all I have done is echo out the responses):</p>
  
  <pre><code>    &lt;?php
  // read the post from PayPal system and add 'cmd'
  $req = 'cmd=_notify-synch';
  
  $tx_token = $_GET['tx'];
  
  $auth_token = "ZdoN6q4GLiRniR2BbOzEEF22GJOWHpVOXRtP7fAhBpvwwm5GyWcTzO_sSSO";
  $req .= "&amp;tx=$tx_token&amp;at=$auth_token";
  
  // 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 ('www.paypal.com', 80, $errno, $errstr, 30);
  // If possible, securely post back to paypal using HTTPS
  // Your PHP server will need to be SSL enabled
  // $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
  
  if (!$fp) 
  {
      // HTTP ERROR
      echo "HTTP Error";
  } 
  else 
  {
      fputs ($fp, $header . $req);
      // read the body data 
      $res = '';
      $headerdone = false;
      while (!feof($fp)) 
      {
          $line = fgets ($fp, 1024);
          if (strcmp($line, "\r\n") == 0) {
              // read the header
              $headerdone = true;
          }
          else if ($headerdone)
          {
              // header has been read. now read the contents
              $res .= $line;
              echo $line;
          }
      }
  
          // parse the data
          $lines = explode("\n", $res);
          $keyarray = array();
          if (strcmp ($lines[0], "SUCCESS") == 0) 
          {
              for ($i=1; $i&lt;count($lines);$i++)
              {
                  list($key,$val) = explode("=", $lines[$i]);
                  $keyarray[urldecode($key)] = urldecode($val);
              }
              // 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
              $firstname = $keyarray['first_name'];
              $lastname = $keyarray['last_name'];
              $itemname = $keyarray['item_name'];
              $amount = $keyarray['payment_gross'];
  
              echo ("&lt;p&gt;&lt;h3&gt;Thank you for your purchase!&lt;/h3&gt;&lt;/p&gt;");
              echo ("&lt;b&gt;Payment Details&lt;/b&gt;&lt;br&gt;\n");
              echo ("&lt;li&gt;Name: $firstname $lastname&lt;/li&gt;\n");
              echo ("&lt;li&gt;Item: $itemname&lt;/li&gt;\n");
              echo ("&lt;li&gt;Amount: $amount&lt;/li&gt;\n");
              echo ("");
          }
          else if (strcmp ($lines[0], "FAIL") == 0) {
              echo "Failure: " . $lines[0];
              // log for manual investigation
          }
  
  }
  
  fclose ($fp);
  
  ?&gt;
  &lt;br /&gt;
  Thank you for your payment. Your transaction has been completed, and a receipt for your purchase has been emailed to you. You may log into your account at &lt;a href="http://www.sandbox.paypal.com/ie"&gt;www.sandbox.paypal.com/ie&lt;/a&gt; to view details of this transaction.
  </code></pre>
  
  <p>I have made sure to confirm the email addresses for both my sandbox merchant and buyer accounts and enabled PDT. </p>
  
  <p>The client is redirected correctly back to my 'thank you' page with the following querystring paramaters - <code>?tx=4FU63684496248523&amp;st=Pending&amp;amt=29.90&amp;cc=EUR&amp;cm=&amp;item_number=</code></p>
  
  <p>Has anyone else encountered this error message? If so, what are the usual causes?</p>