title: How do I make PayPal and cURL work together?
body: <h2>THE BACKGROUND DETAILS:</h2>
  
  <p>I have a custom shopping cart that uses PayPal for payment processing. I have an intermediary page between the cart and PayPal that adds the order to a database and sends confirmation emails.</p>
  
  <p>Until now, I had the intermediary page set up to include all the necessary data as hidden form fields and submit the form to PayPal <code>onload</code>.</p>
  
  <p>Now I'm experimenting with using cURL in PHP to send the POST data to PayPal.</p>
  
  <pre><code>$ch=curl_init();
  curl_setopt($ch, CURLOPT_URL, 'https://www.paypal.com/cgi-bin/webscr');
  //curl_setopt($ch, CURLOPT_URL, 'http://localhost/postecho.php');
  
     // ^ this one is a simple page that echoes all POST data using print_r
  
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $poststring);
  
  // Some options that didn't seem to help
  //curl_setopt($ch, CURLOPT_HEADER, 1);
  //curl_setopt($ch, CURLOPT_POST, 1);
  //curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
  
  // User agent spoofing which also didn't seem to help
  //$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
  //curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  
  $result=curl_exec($ch);
  curl_close($ch);
  </code></pre>
  
  <p><code>$poststring</code> contains all the POST data that I had previously been passing in <code>param1=value&amp;param2=value</code> format. Running this through test page <code>postecho.php</code> reveals that POST data seems to be alright.</p>
  
  <h2>THE PROBLEM:</h2>
  
  <blockquote>
    <p><strong>"Sorry — your last action could not be completed"</strong></p>
  </blockquote>
  
  <p>This is what PayPal tells me when I try to do things the cURL way. It doesn't really give me any helpful information concerning the resolution of this problem. I figure there's gotta be something in the headers or something that it doesn't like. How do I make PayPal and cURL work together?</p>