It is important to add the following to the mix: otherwise, redirecting to the success page does not work:
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
Here is one fully working block of code that is part of Observer.php:
$APIURL = 'https://example.com/submit.php'; $UID = 'username'; $APIKEY = 'password'; $fields = array( 'uid' => $UID, 'apikey' => $APIKEY, 'name' => $customerName, ); //url-ify the data for the POST $fields_string = http_build_query($fields); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL, $APIURL); curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); curl_setopt($ch,CURLOPT_POST, 1); curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string); //execute post curl_exec($ch); //close connection curl_close($ch);
source share